@juice-js/core 1.1.0 → 1.2.0

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.
@@ -1,10 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, Injectable, NgModule, inject, Optional, ɵisPromise as _isPromise, createNgModule, Type, Directive } from '@angular/core';
2
+ import { InjectionToken, Injectable, NgModule, inject, Optional, ɵisPromise as _isPromise, createNgModule, Type, Directive, Inject } from '@angular/core';
3
3
  import { firstValueFrom } from 'rxjs/internal/firstValueFrom';
4
- import { Observable, isObservable, from, of, firstValueFrom as firstValueFrom$1 } from 'rxjs';
4
+ import { Observable, isObservable, from, of, firstValueFrom as firstValueFrom$1, throwError, retry, timer, tap, catchError, finalize, shareReplay } from 'rxjs';
5
5
  import { map, mergeMap } from 'rxjs/operators';
6
6
  import { ROUTES } from '@angular/router';
7
7
  import * as i1 from '@angular/material/dialog';
8
+ import { HttpContextToken, HttpContext, HttpErrorResponse, HttpResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
8
9
 
9
10
  const TENANT_RESOLVER = new InjectionToken('TENANT_RESOLVER');
10
11
  class TenantResolverService {
@@ -465,6 +466,317 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
465
466
  type: Directive
466
467
  }], ctorParameters: () => [{ type: i1.MatDialog }] });
467
468
 
469
+ /**
470
+ * Operation identifier that groups all HTTP attempts belonging to one logical
471
+ * state-changing operation. Requests carrying the same operation id reuse the
472
+ * same `Idempotency-Key` (across double-clicks and retries); a `null` value
473
+ * means the request is not opted into idempotency.
474
+ */
475
+ const IDEMPOTENCY_OPERATION = new HttpContextToken(() => null);
476
+ /**
477
+ * Optional client-side retry horizon (in milliseconds) that bounds how long a
478
+ * key may be reused, mirroring the backend retention window. Past this age the
479
+ * request is surfaced as an expired condition rather than silently treated as new.
480
+ */
481
+ const IDEMPOTENCY_MAX_AGE_MS = new HttpContextToken(() => null);
482
+ /**
483
+ * Build (or extend) an {@link HttpContext} that opts a request into idempotency
484
+ * for the given logical operation.
485
+ *
486
+ * @example
487
+ * this.http.post('/orders', body, { context: withIdempotency('create-order-42') });
488
+ */
489
+ function withIdempotency(operationId, maxAgeMs, context = new HttpContext()) {
490
+ context.set(IDEMPOTENCY_OPERATION, operationId);
491
+ if (maxAgeMs != null) {
492
+ context.set(IDEMPOTENCY_MAX_AGE_MS, maxAgeMs);
493
+ }
494
+ return context;
495
+ }
496
+
497
+ /**
498
+ * Raised when the backend rejects a request because the same `Idempotency-Key`
499
+ * was reused with a materially different payload (HTTP 422).
500
+ */
501
+ class IdempotencyConflictError extends Error {
502
+ constructor(operationId, message = 'Idempotency key conflict: the same key was reused with a different payload.') {
503
+ super(message);
504
+ this.operationId = operationId;
505
+ this.name = 'IdempotencyConflictError';
506
+ }
507
+ }
508
+ /**
509
+ * Raised when an endpoint requires an `Idempotency-Key` but none was supplied
510
+ * (HTTP 400). Should not occur in normal client flow because the interceptor
511
+ * always attaches a key to opted-in requests.
512
+ */
513
+ class IdempotencyKeyRequiredError extends Error {
514
+ constructor(message = 'Idempotency-Key header is required for this request.') {
515
+ super(message);
516
+ this.name = 'IdempotencyKeyRequiredError';
517
+ }
518
+ }
519
+ /**
520
+ * Raised when a key has exceeded its client-side retry horizon and can no longer
521
+ * be safely reused for the same operation.
522
+ */
523
+ class IdempotencyExpiredError extends Error {
524
+ constructor(operationId, message = 'Idempotency key expired; the operation can no longer be safely retried with the same key.') {
525
+ super(message);
526
+ this.operationId = operationId;
527
+ this.name = 'IdempotencyExpiredError';
528
+ }
529
+ }
530
+
531
+ /**
532
+ * Classify an {@link HttpErrorResponse} against the backend idempotency contract
533
+ * (see the Juice backend `011-idempotency-key-api` feature):
534
+ * - `409` → operation is still in progress (retry after backoff)
535
+ * - `422` → key reused with a different payload (conflict)
536
+ * - `400` with an idempotency-key ProblemDetails title → key required
537
+ * - anything else → not an idempotency signal
538
+ */
539
+ function classifyError(error) {
540
+ switch (error.status) {
541
+ case 409:
542
+ return 'in-progress';
543
+ case 422:
544
+ return 'conflict';
545
+ case 400: {
546
+ const title = (error.error && error.error.title) || '';
547
+ return /idempotency[-\s]?key/i.test(title) ? 'required' : 'other';
548
+ }
549
+ default:
550
+ return 'other';
551
+ }
552
+ }
553
+
554
+ /**
555
+ * Optional provider of a user-scoped identifier (e.g. the authenticated subject)
556
+ * folded into the idempotency key scope so keys are never reused across a user
557
+ * switch. Kept as a token so `@juice-js/core` does not depend on `@juice-js/auth`
558
+ * (which would introduce a circular library dependency). Applications with auth
559
+ * provide `{ provide: IDEMPOTENCY_USER_CONTEXT, useValue: () => oauth.getIdentityClaims()?.sub ?? null }`.
560
+ */
561
+ const IDEMPOTENCY_USER_CONTEXT = new InjectionToken('IDEMPOTENCY_USER_CONTEXT');
562
+ /**
563
+ * Generates, stores, and reuses a collision-resistant `Idempotency-Key` per
564
+ * logical operation. The same operation id yields the same key across retries
565
+ * and double-submits; distinct operations get distinct keys; and keys are scoped
566
+ * to the current tenant/user so they never leak across a context switch.
567
+ */
568
+ class IdempotencyKeyService {
569
+ constructor(tenant, userContext) {
570
+ this.tenant = tenant;
571
+ this.userContext = userContext;
572
+ this.entries = new Map();
573
+ }
574
+ currentScope() {
575
+ const t = this.tenant?.currentTenant?.identifier ?? this.tenant?.requestTenantIdentifier ?? '';
576
+ const u = this.userContext?.() ?? '';
577
+ return `${t}|${u}`;
578
+ }
579
+ newKey() {
580
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
581
+ return crypto.randomUUID();
582
+ }
583
+ // Fallback RFC4122-style generator for environments without crypto.randomUUID.
584
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
585
+ const r = (Math.random() * 16) | 0;
586
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
587
+ return v.toString(16);
588
+ });
589
+ }
590
+ /**
591
+ * Return the existing key for this operation, or generate a new one. If the
592
+ * current tenant/user scope differs from the stored entry, a fresh key is
593
+ * generated (FR-010).
594
+ */
595
+ getKey(operationId) {
596
+ const scope = this.currentScope();
597
+ const existing = this.entries.get(operationId);
598
+ if (existing && existing.scope === scope) {
599
+ return existing.key;
600
+ }
601
+ const entry = { key: this.newKey(), scope, createdAt: Date.now(), inFlight: false };
602
+ this.entries.set(operationId, entry);
603
+ return entry.key;
604
+ }
605
+ /** Forget the key for a completed (or abandoned) operation. */
606
+ release(operationId) {
607
+ this.entries.delete(operationId);
608
+ }
609
+ /**
610
+ * Whether the stored key for the operation has exceeded the given retry
611
+ * horizon. Returns `false` when no horizon is set or no key exists yet.
612
+ */
613
+ isExpired(operationId, maxAgeMs) {
614
+ if (maxAgeMs == null) {
615
+ return false;
616
+ }
617
+ const entry = this.entries.get(operationId);
618
+ if (!entry) {
619
+ return false;
620
+ }
621
+ return Date.now() - entry.createdAt > maxAgeMs;
622
+ }
623
+ /**
624
+ * UI-level double-submit guard (FR-009). Returns `false` if an operation is
625
+ * already in flight, so callers can suppress a duplicate dispatch.
626
+ */
627
+ tryBeginInFlight(operationId) {
628
+ const scope = this.currentScope();
629
+ const entry = this.entries.get(operationId) ?? { key: this.newKey(), scope, createdAt: Date.now(), inFlight: false };
630
+ if (entry.inFlight) {
631
+ return false;
632
+ }
633
+ entry.inFlight = true;
634
+ this.entries.set(operationId, entry);
635
+ return true;
636
+ }
637
+ /** Clear the in-flight flag set by {@link tryBeginInFlight}. */
638
+ endInFlight(operationId) {
639
+ const entry = this.entries.get(operationId);
640
+ if (entry) {
641
+ entry.inFlight = false;
642
+ }
643
+ }
644
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: IdempotencyKeyService, deps: [{ token: TenantService, optional: true }, { token: IDEMPOTENCY_USER_CONTEXT, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
645
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: IdempotencyKeyService, providedIn: 'root' }); }
646
+ }
647
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: IdempotencyKeyService, decorators: [{
648
+ type: Injectable,
649
+ args: [{ providedIn: 'root' }]
650
+ }], ctorParameters: () => [{ type: TenantService, decorators: [{
651
+ type: Optional
652
+ }] }, { type: undefined, decorators: [{
653
+ type: Optional
654
+ }, {
655
+ type: Inject,
656
+ args: [IDEMPOTENCY_USER_CONTEXT]
657
+ }] }] });
658
+
659
+ /**
660
+ * Attaches an `Idempotency-Key` header to opted-in state-changing requests and
661
+ * interprets the backend idempotency responses:
662
+ * - replayed success is passed through and the key released;
663
+ * - `409` in-progress triggers a bounded backoff retry reusing the same key;
664
+ * - `422` conflict and `400` required surface as typed errors without resubmission;
665
+ * - keys past their retry horizon surface as an expired error.
666
+ *
667
+ * On top of the shared key, it de-duplicates concurrent dispatches of the same
668
+ * operation (FR-009): while one attempt is in flight, a second subscription to
669
+ * the same operation is coalesced onto the first in-flight response instead of
670
+ * issuing a parallel request, so a double-click settles on a single outcome.
671
+ *
672
+ * Mirrors the `@juice-js/auth` `AuthInterceptor` idiom.
673
+ */
674
+ class IdempotencyInterceptor {
675
+ constructor(keys) {
676
+ this.keys = keys;
677
+ this.maxInProgressRetries = 3;
678
+ this.baseBackoffMs = 500;
679
+ /**
680
+ * Shared, in-flight response streams keyed by operation id. Present only while
681
+ * an operation is being sent; cleared when it settles (success or error).
682
+ */
683
+ this.inFlight = new Map();
684
+ }
685
+ isUnsafe(method) {
686
+ const m = method.toUpperCase();
687
+ return m === 'POST' || m === 'PUT' || m === 'PATCH' || m === 'DELETE';
688
+ }
689
+ intercept(req, next) {
690
+ const operationId = req.context.get(IDEMPOTENCY_OPERATION);
691
+ // Not opted in, or a safe/read-only request → pass through untouched (FR-004).
692
+ if (!operationId || !this.isUnsafe(req.method)) {
693
+ return next.handle(req);
694
+ }
695
+ const maxAgeMs = req.context.get(IDEMPOTENCY_MAX_AGE_MS);
696
+ if (this.keys.isExpired(operationId, maxAgeMs)) {
697
+ this.keys.release(operationId);
698
+ return throwError(() => new IdempotencyExpiredError(operationId));
699
+ }
700
+ // FR-009: a duplicate dispatch while the operation is in flight rides the
701
+ // existing response instead of firing a parallel request.
702
+ const existing = this.inFlight.get(operationId);
703
+ if (existing) {
704
+ return existing;
705
+ }
706
+ const key = this.keys.getKey(operationId);
707
+ const idempotentReq = req.clone({ headers: req.headers.set('Idempotency-Key', key) });
708
+ const shared = next.handle(idempotentReq).pipe(retry({
709
+ count: this.maxInProgressRetries,
710
+ delay: (error, retryCount) => {
711
+ // Only retry the in-progress signal; every other error propagates immediately.
712
+ if (!(error instanceof HttpErrorResponse) || classifyError(error) !== 'in-progress') {
713
+ throw error;
714
+ }
715
+ return timer(this.baseBackoffMs * Math.pow(2, retryCount - 1));
716
+ },
717
+ }), tap((event) => {
718
+ if (event instanceof HttpResponse) {
719
+ this.keys.release(operationId);
720
+ }
721
+ }), catchError((error) => {
722
+ if (error instanceof HttpErrorResponse) {
723
+ switch (classifyError(error)) {
724
+ case 'conflict':
725
+ this.keys.release(operationId);
726
+ return throwError(() => new IdempotencyConflictError(operationId));
727
+ case 'required':
728
+ this.keys.release(operationId);
729
+ return throwError(() => new IdempotencyKeyRequiredError());
730
+ case 'in-progress':
731
+ // Retries exhausted while still in progress — surface the original error,
732
+ // keeping the key so a later manual retry can reuse it within retention.
733
+ return throwError(() => error);
734
+ default:
735
+ return throwError(() => error);
736
+ }
737
+ }
738
+ return throwError(() => error);
739
+ }),
740
+ // Drop the coalescing entry once the operation settles so the next dispatch
741
+ // starts a fresh attempt. With refCount:false below this fires on terminal
742
+ // success or error, not on a subscriber leaving mid-flight.
743
+ finalize(() => this.inFlight.delete(operationId)),
744
+ // Multicast the single attempt to every coalesced subscriber; refCount:false
745
+ // keeps the request running even if the initial subscriber unsubscribes.
746
+ shareReplay({ bufferSize: 1, refCount: false }));
747
+ this.inFlight.set(operationId, shared);
748
+ return shared;
749
+ }
750
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: IdempotencyInterceptor, deps: [{ token: IdempotencyKeyService }], target: i0.ɵɵFactoryTarget.Injectable }); }
751
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: IdempotencyInterceptor }); }
752
+ }
753
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: IdempotencyInterceptor, decorators: [{
754
+ type: Injectable
755
+ }], ctorParameters: () => [{ type: IdempotencyKeyService }] });
756
+
757
+ /**
758
+ * Registers the {@link IdempotencyInterceptor} so opted-in state-changing
759
+ * requests automatically carry an `Idempotency-Key` header.
760
+ *
761
+ * @example
762
+ * imports: [IdempotencyModule]
763
+ */
764
+ class IdempotencyModule {
765
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: IdempotencyModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
766
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.0.6", ngImport: i0, type: IdempotencyModule }); }
767
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: IdempotencyModule, providers: [
768
+ { provide: HTTP_INTERCEPTORS, useClass: IdempotencyInterceptor, multi: true },
769
+ ] }); }
770
+ }
771
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: IdempotencyModule, decorators: [{
772
+ type: NgModule,
773
+ args: [{
774
+ providers: [
775
+ { provide: HTTP_INTERCEPTORS, useClass: IdempotencyInterceptor, multi: true },
776
+ ],
777
+ }]
778
+ }] });
779
+
468
780
  /*
469
781
  * Public API Surface of core
470
782
  */
@@ -473,5 +785,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
473
785
  * Generated bundle index. Do not edit.
474
786
  */
475
787
 
476
- export { AsyncDialog, MENUS, MenuItem, MenuModule, MenuService, TenantModule, TenantService, loadChildrenRoutes };
788
+ export { AsyncDialog, IDEMPOTENCY_MAX_AGE_MS, IDEMPOTENCY_OPERATION, IDEMPOTENCY_USER_CONTEXT, IdempotencyConflictError, IdempotencyExpiredError, IdempotencyInterceptor, IdempotencyKeyRequiredError, IdempotencyKeyService, IdempotencyModule, MENUS, MenuItem, MenuModule, MenuService, TenantModule, TenantService, classifyError, loadChildrenRoutes, withIdempotency };
477
789
  //# sourceMappingURL=juice-js-core.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"juice-js-core.mjs","sources":["../../../../projects/juice-js/core/src/lib/tenant/tenant-resolver.service.ts","../../../../projects/juice-js/core/src/lib/tenant/resolvers/config-resolver.service.ts","../../../../projects/juice-js/core/src/lib/tenant/tenant.module.ts","../../../../projects/juice-js/core/src/lib/tenant/resolvers/storage-resolver.service.ts","../../../../projects/juice-js/core/src/lib/tenant/tenant.service.ts","../../../../projects/juice-js/core/src/lib/menu/utils.ts","../../../../projects/juice-js/core/src/lib/menu/menu-loader.ts","../../../../projects/juice-js/core/src/lib/menu/menu-item.ts","../../../../projects/juice-js/core/src/lib/menu/menu.service.ts","../../../../projects/juice-js/core/src/lib/menu/menu.module.ts","../../../../projects/juice-js/core/src/lib/routing/utils.ts","../../../../projects/juice-js/core/src/lib/extensions/string.extensions.ts","../../../../projects/juice-js/core/src/lib/dialog/async-dialog.service.ts","../../../../projects/juice-js/core/src/public-api.ts","../../../../projects/juice-js/core/src/juice-js-core.ts"],"sourcesContent":["import { Injectable, InjectionToken } from '@angular/core';\nimport { Observable } from 'rxjs/internal/Observable';\nimport { TenantInfo } from './tenant-info';\n\nexport const TENANT_RESOLVER = new InjectionToken<TenantResolverService[]>('TENANT_RESOLVER');\n\n@Injectable({\n providedIn: 'root'\n})\nexport abstract class TenantResolverService {\n\n priority = 0;\n abstract getTenantByIdentifier(identifier: string): Observable<TenantInfo|null>;\n}\n","\nimport { Observable } from 'rxjs';\nimport { TenantResolverService } from '../tenant-resolver.service';\nimport { TenantInfo } from '../tenant-info';\n\nexport class ConfigResolver extends TenantResolverService{\n override priority: number = 99;\n constructor(private config: TenantInfo[]){\n super();\n }\n\n getTenantByIdentifier(identifier: string): Observable<TenantInfo|null> {\n if(identifier===''){\n return new Observable(subscriber => {\n subscriber.next({identifier:''} as TenantInfo);\n subscriber.complete();\n });\n }\n const tenant = this.config.find(tenant => tenant.identifier === identifier);\n if(tenant){\n return new Observable(subscriber => {\n subscriber.next(tenant);\n subscriber.complete();\n });\n }\n return new Observable(subscriber => {\n subscriber.next(null);\n subscriber.complete();\n });\n }\n}","import { ModuleWithProviders, NgModule } from '@angular/core';\nimport { TenantService } from './tenant.service';\nimport { TENANT_RESOLVER } from './tenant-resolver.service';\nimport { ConfigResolver } from './resolvers/config-resolver.service';\nimport { StorageResolver } from './resolvers/storage-resolver.service';\nimport { TenantInfo } from './tenant-info';\n\n@NgModule({\n})\nexport class TenantModule { \n public static forRoot(tenants: TenantInfo[] = []): ModuleWithProviders<TenantModule>{\n return {\n ngModule: TenantModule,\n providers: [\n TenantService,\n {\n provide: TENANT_RESOLVER,\n useValue: new ConfigResolver(tenants),\n multi: true\n },\n {\n provide: TENANT_RESOLVER,\n useClass: StorageResolver,\n multi: true\n }\n ]\n }\n }\n}\n","\nimport { Injectable } from '@angular/core';\nimport { Observable } from 'rxjs';\nimport { TenantResolverService } from '../tenant-resolver.service';\nimport { TenantModule } from '../tenant.module';\nimport { TenantInfo } from '../tenant-info';\n\n@Injectable({\n providedIn: TenantModule\n})\nexport class StorageResolver extends TenantResolverService{\n static CURRENT_TENANT = '_TENANT_';\n override priority: number = 100;\n constructor(){\n super();\n }\n\n getTenantByIdentifier(identifier: string): Observable<TenantInfo|null> {\n var currentTenant = localStorage.getItem(StorageResolver.CURRENT_TENANT);\n var tenantInfo = currentTenant ? JSON.parse(currentTenant) as TenantInfo : null;\n if(tenantInfo && tenantInfo.identifier === identifier){\n return new Observable(subscriber => {\n subscriber.next(tenantInfo);\n subscriber.complete();\n });\n }\n return new Observable(subscriber => {\n subscriber.next(null);\n subscriber.complete();\n });\n }\n\n saveTenant(tenant: TenantInfo){\n localStorage.setItem(StorageResolver.CURRENT_TENANT, JSON.stringify(tenant));\n }\n\n clearTenant(){\n localStorage.removeItem(StorageResolver.CURRENT_TENANT);\n }\n\n getCurrentTenant(): TenantInfo|null{\n var currentTenant = localStorage.getItem(StorageResolver.CURRENT_TENANT);\n return currentTenant ? JSON.parse(currentTenant) as TenantInfo : null;\n }\n}","import { Inject, Injectable, Optional, inject } from '@angular/core';\nimport { firstValueFrom } from 'rxjs/internal/firstValueFrom';\nimport { TENANT_RESOLVER, TenantResolverService } from './tenant-resolver.service';\nimport { TenantInfo } from './tenant-info';\nimport { StorageResolver } from './resolvers/storage-resolver.service';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class TenantService {\n currentTenant: TenantInfo|null = null;\n requestTenantIdentifier: string|null = null;\n resolvers: TenantResolverService[] = [];\n storageResolver: StorageResolver|undefined;\n constructor(\n @Optional() storageResolver: StorageResolver\n ) { \n this.resolvers = inject(TENANT_RESOLVER, {optional: true}) ?? [];\n this.storageResolver = storageResolver;\n this.currentTenant = this.storageResolver?.getCurrentTenant();\n }\n\n async getTenantIdentifier(){\n return (await this.getTenantInfo())?.identifier\n ;\n }\n\n private async getTenantByIdentifier(identifier: string): Promise<TenantInfo|null>{\n if(!this.resolvers){\n return null;\n }\n for(const resolver of this.resolvers.sort((a,b) => b.priority - a.priority)){\n // console.debug(`Resolving tenant ${identifier} by ${resolver.constructor.name}`);\n var tenant = await firstValueFrom(resolver.getTenantByIdentifier(identifier));\n if(tenant){\n tenant.resolvedBy = resolver.constructor.name;\n console.debug(`Tenant ${tenant.identifier} resolved by ${tenant.resolvedBy}`);\n if(!(resolver instanceof StorageResolver) || tenant.identifier != this.currentTenant?.identifier){\n this.storageResolver?.saveTenant(tenant);\n this.currentTenant = tenant;\n }\n return tenant;\n }\n }\n return null;\n }\n\n async getTenantInfo(): Promise<TenantInfo|null>{\n // :tenant/:module/:component\n var tenant = window.location.pathname.split('/')[1];\n this.requestTenantIdentifier = tenant;\n return (await this.getTenantByIdentifier(tenant))\n ?? this.storedTenant()\n ?? null\n ;\n }\n\n storedTenant(): TenantInfo|null|undefined{\n return this.storageResolver?.getCurrentTenant();\n }\n\n isMatched(): boolean{\n return this.currentTenant?.identifier == this.requestTenantIdentifier;\n }\n}\n","import {ɵisPromise as isPromise} from '@angular/core';\nimport {from, isObservable, Observable, of} from 'rxjs';\n\n\nexport function wrapIntoObservable<T>(value: T|Promise<T>|Observable<T>): Observable<T> {\n if (isObservable(value)) {\n return value;\n }\n \n if (isPromise(value)) {\n // Use `Promise.resolve()` to wrap promise-like instances.\n // Required ie when a Resolver returns a AngularJS `$q` promise to correctly trigger the\n // change detection.\n return from(Promise.resolve(value));\n }\n \n return of(value);\n }\n","\nimport { Injector, Type, createNgModule } from '@angular/core';\nimport { wrapIntoObservable} from './utils';\nimport { MENUS, MenuItem, Menus, CanDisplay } from './menu-item';\nimport { map } from 'rxjs/operators';\nimport { Observable, of, firstValueFrom } from 'rxjs';\nimport { ROUTES, Route } from '@angular/router';\n\nexport interface DefaultExport<T> {\n default: T;\n}\n\nexport async function loadChildren(menu: MenuItem, parentInjector: Injector, \n tenant: string|null|undefined): Promise<void>\n{\n if(menu.loaded){\n menu.injectTenant(tenant);\n return;\n }\n // console.debug(\"loadChildren\", menu.rawRouterLink);\n if(!hasChildren(menu)){\n return;\n }\n await loadChildrenInternal(menu, parentInjector, tenant)\n .then(children => {\n if(children!=null){\n console.debug(\"loadedChildren\", menu.rawRouterLink, children.map(c => c.rawRouterLink));\n menu.children = children;\n menu.injectTenant(tenant);\n }\n menu.loaded = true;\n })\n ;\n}\n\nasync function loadChildrenInternal(menu: MenuItem, parentInjector: Injector, tenant: string|null|undefined)\n: Promise<MenuItem[]>{\n \n var result: MenuItem[] = [];\n var children = await firstValueFrom(getChildren(menu, parentInjector, tenant));\n for(let child of children){\n if(hasChildren(child)){\n var sub = await loadChildrenInternal(child, parentInjector, tenant);\n if(sub.length > 0){\n result = result.concat(sub);\n }\n }else{\n result.push(child);\n }\n }\n \n return result.map(child => {\n child.rawRouterLink = menu.replaceChildRouterLink && menu.rawRouterLink ?\n ('/' + menu.rawRouterLink.trimSlash() + '/' + child.rawRouterLink.trimSlash()).trimEndSlash()\n : '/'+child.rawRouterLink.trimSlash();\n return child;\n });\n}\n\nfunction hasChildren(menu: MenuItem): boolean{\n return !((menu.children == null || menu.children.length==0) && !menu.loadChildren);\n}\n\nfunction getChildren(menu:MenuItem, parentInjector: Injector, tenant: string|null|undefined) \n : Observable<MenuItem[]>{\n if(menu.loadChildren){\n return wrapIntoObservable(menu.loadChildren())\n .pipe(\n map(t => loadMenus(t, parentInjector))\n );\n }else{\n return of(menu.children.filter(m => filterMenu(m, parentInjector)));\n }\n}\n\nfunction loadMenus(menusOrModule: Type<unknown>|Menus, parentInjector: Injector): MenuItem[] {\n \n if(Array.isArray(menusOrModule)){\n return menusOrModule.map(menu => new MenuItem(menu));\n }\n const module = createNgModule(menusOrModule, parentInjector);\n const injector = module.injector;\n const menus = injector.get(MENUS, [], {optional: true, self: true}).flat();\n const routes = injector.get(ROUTES, [], {optional: true, self: true});\n var routeMenus = mapRouteMenu(routes);\n // console.debug(\"loadMenus\", menus, routeMenus);\n return menus.map(menu => new MenuItem(menu)).concat(routeMenus)\n .filter(m => filterMenu(m, injector));\n}\n\nfunction filterMenu(menu: MenuItem, injector: Injector): boolean{\n\n if(menu.canDisplay instanceof Boolean){\n return menu.canDisplay as boolean;\n }\n const canDisplays = getCanDisplays(menu.canDisplay);\n\n return (canDisplays.length === 0 || canDisplays.every(\n (c: any) => {\n if(c instanceof Type){\n const service = injector.get<CanDisplay>(c as Type<CanDisplay>);\n return service.canDisplay();\n }else if(c instanceof Function){\n return c();\n }\n return true;\n }\n ))\n}\n\nfunction getCanDisplays(canDisplay: boolean|any[]): Array<any>{\n if(canDisplay instanceof Boolean){\n return [];\n }\n return Array.isArray(canDisplay) ? canDisplay : [];\n}\n\nexport function mapRouteMenu(routes: Route[][]): MenuItem[]{\n return routes\n .map(route => route.filter(isMenu).map(r => {\n if(!r.data){\n r.data = {};\n }\n return MenuItem.fromRoute(r);\n })\n ).flatMap(m => m.map(r => r!));\n}\n\nexport function isMenu(route: Route): boolean{\n return route.data && (route.data['menuDisplay'] || route.data['menuWrapper']);\n}\n","import { InjectionToken } from '@angular/core';\nimport { Route } from '@angular/router';\nimport { isMenu } from './menu-loader';\n\nexport class MenuItem {\n id: string = \"\";\n label: string = \"\";\n routerLink: string = \"\";\n rawRouterLink: string;\n icon: string = \"\";\n order: number = 0;\n children: MenuItem[];\n loadChildren?: Function;\n replaceChildRouterLink: boolean;\n loaded: boolean = false;\n canDisplay: any[] | boolean;\n \n constructor(menu: Menu){\n this.id = menu.id;\n this.label = menu.label;\n this.routerLink = menu.routerLink;\n this.icon = menu.icon;\n this.order = menu.order??0;\n this.children = menu.children?.map(m => new MenuItem(m))?? [];\n this.loadChildren = menu.loadChildren;\n this.replaceChildRouterLink = menu.replaceChildRouterLink ?? true;\n this.loaded = false;\n this.rawRouterLink = menu.routerLink;\n this.canDisplay = menu.canDisplay??[];\n }\n\n static fromRoute(route: Route): MenuItem{\n var menu = new MenuItem({\n id: route.path ?? '',\n label: route.data!['menuTitle']??route.title??route.path??'',\n routerLink: route.path??'',\n icon: route.data!['menuIcon']??'',\n order: route.data!['menuOrder']??0,\n children: route.children?.filter(isMenu).map(r => MenuItem.fromRoute(r))??[],\n loadChildren: route.loadChildren,\n replaceChildRouterLink: true,\n canDisplay: (route.data!['menuDisplay'] as boolean | any[])\n });\n return menu;\n }\n\n hasChildren(): boolean{\n return this.children.length > 0;\n }\n\n injectTenant(tenant: string|null|undefined){\n this.children?.forEach(item => {\n if(item.hasChildren()){\n item.injectTenant(tenant);\n }else{\n item.routerLink = item.rawRouterLink.injectTenant(tenant);\n }\n });\n this.routerLink = this.rawRouterLink.injectTenant(tenant);\n }\n}\n\nexport interface Menu {\n id: string,\n label: string,\n routerLink: string,\n icon: string,\n order?: number,\n children?: Menus,\n loadChildren?: any,\n replaceChildRouterLink?: boolean,\n canDisplay?: any[] | boolean\n}\n\nexport type Menus = Menu[];\n\nexport const MENUS = new InjectionToken<Menus[]>('MENUS');\n\nexport interface CanDisplay{\n canDisplay(): boolean;\n}","import { Injectable, Injector, inject } from '@angular/core';\nimport { MENUS, MenuItem } from './menu-item';\nimport { Observable, of } from 'rxjs';\nimport { map, mergeMap } from 'rxjs/operators';\nimport { loadChildren, mapRouteMenu } from './menu-loader';\nimport { TenantService } from '../tenant/tenant.service';\nimport { ROUTES, Route } from '@angular/router';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class MenuService {\n routes: Route[][] = [];\n constructor(private injector: Injector, private tenantService: TenantService) { \n this.routes = inject(ROUTES, {optional: true})??[];\n }\n\n getMenu():Observable<MenuItem[]>{\n var menus = this.injector.get(MENUS, [], {optional: true, self: true}).flat();\n var routeMenus = mapRouteMenu(this.routes);\n // console.debug(\"getMenu\", menus, routeMenus, this.routes);\n return of(menus)\n .pipe(\n map(menus => menus.map(m => new MenuItem(m))),\n map(async menus => {\n var tenant = await this.tenantService.getTenantIdentifier();\n let menuItems = [];\n for(let menu of menus.concat(routeMenus)){\n await loadChildren(menu, this.injector, tenant);\n menuItems.push(menu);\n }\n return menuItems;\n }),\n mergeMap(menus => menus),\n map(menus => menus.sort((a,b) => (a.order ?? 0) - (b.order ?? 0)))\n );\n }\n\n}\n","import { ModuleWithProviders, NgModule } from '@angular/core';\nimport { MenuService } from './menu.service';\nimport { MENUS, Menus } from './menu-item';\n\n@NgModule({\n declarations: [\n\n ],\n imports: [\n \n ],\n exports: [\n\n ]\n})\nexport class MenuModule {\n\n /**\n * Creates and configures a module with all the menu providers.\n * Optionally sets up an application listener to perform an initial navigation.\n *\n * When registering the NgModule at the root, import as follows:\n *\n * ```\n * @NgModule({\n * imports: [MenuModule.forRoot(MENUS)]\n * })\n * class MyNgModule {}\n * ```\n *\n * @param menus An array of `Route` objects that define the navigation paths for the application.\n * @return The new `NgModule`.\n *\n */\n public static forRoot(menus: Menus): ModuleWithProviders<MenuModule> {\n \n return {\n ngModule: MenuModule,\n providers: [\n MenuService,\n {\n provide: MENUS,\n multi: true,\n useValue: menus\n }\n ]\n };\n }\n\n /**\n * Creates a module with all the menus, without creating a new Router service.\n * When registering for submodules and lazy-loaded submodules, create the NgModule as follows:\n *\n * ```\n * @NgModule({\n * imports: [MenuModule.forChild(MENUS)]\n * })\n * class MyNgModule {}\n * ```\n *\n * @param menus An array of `MenuItem` objects that define the navigation paths for the submodule.\n * @return The new NgModule.\n *\n */\n public static forChild(menus: Menus): ModuleWithProviders<MenuModule> {\n return {\n ngModule: MenuModule,\n providers: [{provide: MENUS, multi: true, useValue: menus}],\n }\n }\n \n}","import { ROUTES, Routes } from \"@angular/router\";\nimport { ModuleWithProviders, Type, createNgModule } from \"@angular/core\";\n\nexport function loadChildrenRoutes(menusOrModule: ModuleWithProviders<any>): Routes {\n \n const module = createNgModule(menusOrModule.ngModule);\n const injector = module.injector;\n const menus = injector.get(ROUTES, [], {optional: true, self: true}).flat();\n return menus;\n}","export { };\ndeclare global {\n interface String {\n trimStartSlash(): string;\n trimEndSlash(): string;\n trimSlash(): string;\n injectTenant(tenant: string|null|undefined): string;\n }\n}\nString.prototype.trimStartSlash = function (): string{\n return this.replace(/^[\\/]+/, '');\n}\nString.prototype.trimEndSlash = function (): string{\n return this.replace(/[\\/]+$/, '');\n}\nString.prototype.trimSlash = function (): string{\n return this.trimStartSlash().trimEndSlash();\n}\nString.prototype.injectTenant = function (tenant: string|null|undefined): string{\n return '/' + this.replace(':tenant', tenant??'').trimStartSlash();\n}\n","import { MatDialog, MatDialogRef } from '@angular/material/dialog';\nimport { Directive } from '@angular/core';\n\n@Directive()\nexport abstract class AsyncDialog<ComponentType, DataType, ReturnType = unknown> {\n constructor(protected matDialog: MatDialog) {\n }\n\n abstract open(data: DataType): Promise<MatDialogRef<ComponentType, ReturnType>>;\n}","/*\n * Public API Surface of core\n */\n\nexport * from './lib/tenant/tenant.service';\nexport * from './lib/tenant/tenant.module';\nexport * from './lib/tenant/tenant-info';\nexport * from './lib/menu/menu.service';\nexport * from './lib/menu/menu.module';\nexport * from './lib/menu/menu-item';\nexport * from './lib/routing/utils';\nexport * from './lib/extensions/index';\nexport * from './lib/dialog/async-dialog.service';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.StorageResolver","isPromise","firstValueFrom","i1.TenantService"],"mappings":";;;;;;;;AAIO,MAAM,eAAe,GAAG,IAAI,cAAc,CAA0B,iBAAiB,CAAC;MAKvE,qBAAqB,CAAA;AAH3C,IAAA,WAAA,GAAA;QAKE,IAAA,CAAA,QAAQ,GAAG,CAAC;AAEb,IAAA;8GAJqB,qBAAqB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAArB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,qBAAqB,cAF7B,MAAM,EAAA,CAAA,CAAA;;2FAEE,qBAAqB,EAAA,UAAA,EAAA,CAAA;kBAH1C,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;;ACHK,MAAO,cAAe,SAAQ,qBAAqB,CAAA;AAErD,IAAA,WAAA,CAAoB,MAAoB,EAAA;AACpC,QAAA,KAAK,EAAE;QADS,IAAA,CAAA,MAAM,GAAN,MAAM;QADjB,IAAA,CAAA,QAAQ,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KAAA,EAAA,EAAA,CAAA,SAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;kGAAX,WAAW,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA,CAAA;;2FAAX,WAAW,EAAA,UAAA,EAAA,CAAA;kBADhC;;;ACHD;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"juice-js-core.mjs","sources":["../../../../projects/juice-js/core/src/lib/tenant/tenant-resolver.service.ts","../../../../projects/juice-js/core/src/lib/tenant/resolvers/config-resolver.service.ts","../../../../projects/juice-js/core/src/lib/tenant/tenant.module.ts","../../../../projects/juice-js/core/src/lib/tenant/resolvers/storage-resolver.service.ts","../../../../projects/juice-js/core/src/lib/tenant/tenant.service.ts","../../../../projects/juice-js/core/src/lib/menu/utils.ts","../../../../projects/juice-js/core/src/lib/menu/menu-loader.ts","../../../../projects/juice-js/core/src/lib/menu/menu-item.ts","../../../../projects/juice-js/core/src/lib/menu/menu.service.ts","../../../../projects/juice-js/core/src/lib/menu/menu.module.ts","../../../../projects/juice-js/core/src/lib/routing/utils.ts","../../../../projects/juice-js/core/src/lib/extensions/string.extensions.ts","../../../../projects/juice-js/core/src/lib/dialog/async-dialog.service.ts","../../../../projects/juice-js/core/src/lib/http/idempotency/idempotency.context.ts","../../../../projects/juice-js/core/src/lib/http/idempotency/idempotency.errors.ts","../../../../projects/juice-js/core/src/lib/http/idempotency/idempotency-response.ts","../../../../projects/juice-js/core/src/lib/http/idempotency/idempotency-key.service.ts","../../../../projects/juice-js/core/src/lib/http/idempotency/idempotency.interceptor.ts","../../../../projects/juice-js/core/src/lib/http/idempotency/idempotency.module.ts","../../../../projects/juice-js/core/src/public-api.ts","../../../../projects/juice-js/core/src/juice-js-core.ts"],"sourcesContent":["import { Injectable, InjectionToken } from '@angular/core';\nimport { Observable } from 'rxjs/internal/Observable';\nimport { TenantInfo } from './tenant-info';\n\nexport const TENANT_RESOLVER = new InjectionToken<TenantResolverService[]>('TENANT_RESOLVER');\n\n@Injectable({\n providedIn: 'root'\n})\nexport abstract class TenantResolverService {\n\n priority = 0;\n abstract getTenantByIdentifier(identifier: string): Observable<TenantInfo|null>;\n}\n","\nimport { Observable } from 'rxjs';\nimport { TenantResolverService } from '../tenant-resolver.service';\nimport { TenantInfo } from '../tenant-info';\n\nexport class ConfigResolver extends TenantResolverService{\n override priority: number = 99;\n constructor(private config: TenantInfo[]){\n super();\n }\n\n getTenantByIdentifier(identifier: string): Observable<TenantInfo|null> {\n if(identifier===''){\n return new Observable(subscriber => {\n subscriber.next({identifier:''} as TenantInfo);\n subscriber.complete();\n });\n }\n const tenant = this.config.find(tenant => tenant.identifier === identifier);\n if(tenant){\n return new Observable(subscriber => {\n subscriber.next(tenant);\n subscriber.complete();\n });\n }\n return new Observable(subscriber => {\n subscriber.next(null);\n subscriber.complete();\n });\n }\n}","import { ModuleWithProviders, NgModule } from '@angular/core';\nimport { TenantService } from './tenant.service';\nimport { TENANT_RESOLVER } from './tenant-resolver.service';\nimport { ConfigResolver } from './resolvers/config-resolver.service';\nimport { StorageResolver } from './resolvers/storage-resolver.service';\nimport { TenantInfo } from './tenant-info';\n\n@NgModule({\n})\nexport class TenantModule { \n public static forRoot(tenants: TenantInfo[] = []): ModuleWithProviders<TenantModule>{\n return {\n ngModule: TenantModule,\n providers: [\n TenantService,\n {\n provide: TENANT_RESOLVER,\n useValue: new ConfigResolver(tenants),\n multi: true\n },\n {\n provide: TENANT_RESOLVER,\n useClass: StorageResolver,\n multi: true\n }\n ]\n }\n }\n}\n","\nimport { Injectable } from '@angular/core';\nimport { Observable } from 'rxjs';\nimport { TenantResolverService } from '../tenant-resolver.service';\nimport { TenantModule } from '../tenant.module';\nimport { TenantInfo } from '../tenant-info';\n\n@Injectable({\n providedIn: TenantModule\n})\nexport class StorageResolver extends TenantResolverService{\n static CURRENT_TENANT = '_TENANT_';\n override priority: number = 100;\n constructor(){\n super();\n }\n\n getTenantByIdentifier(identifier: string): Observable<TenantInfo|null> {\n var currentTenant = localStorage.getItem(StorageResolver.CURRENT_TENANT);\n var tenantInfo = currentTenant ? JSON.parse(currentTenant) as TenantInfo : null;\n if(tenantInfo && tenantInfo.identifier === identifier){\n return new Observable(subscriber => {\n subscriber.next(tenantInfo);\n subscriber.complete();\n });\n }\n return new Observable(subscriber => {\n subscriber.next(null);\n subscriber.complete();\n });\n }\n\n saveTenant(tenant: TenantInfo){\n localStorage.setItem(StorageResolver.CURRENT_TENANT, JSON.stringify(tenant));\n }\n\n clearTenant(){\n localStorage.removeItem(StorageResolver.CURRENT_TENANT);\n }\n\n getCurrentTenant(): TenantInfo|null{\n var currentTenant = localStorage.getItem(StorageResolver.CURRENT_TENANT);\n return currentTenant ? JSON.parse(currentTenant) as TenantInfo : null;\n }\n}","import { Inject, Injectable, Optional, inject } from '@angular/core';\nimport { firstValueFrom } from 'rxjs/internal/firstValueFrom';\nimport { TENANT_RESOLVER, TenantResolverService } from './tenant-resolver.service';\nimport { TenantInfo } from './tenant-info';\nimport { StorageResolver } from './resolvers/storage-resolver.service';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class TenantService {\n currentTenant: TenantInfo|null = null;\n requestTenantIdentifier: string|null = null;\n resolvers: TenantResolverService[] = [];\n storageResolver: StorageResolver|undefined;\n constructor(\n @Optional() storageResolver: StorageResolver\n ) { \n this.resolvers = inject(TENANT_RESOLVER, {optional: true}) ?? [];\n this.storageResolver = storageResolver;\n this.currentTenant = this.storageResolver?.getCurrentTenant();\n }\n\n async getTenantIdentifier(){\n return (await this.getTenantInfo())?.identifier\n ;\n }\n\n private async getTenantByIdentifier(identifier: string): Promise<TenantInfo|null>{\n if(!this.resolvers){\n return null;\n }\n for(const resolver of this.resolvers.sort((a,b) => b.priority - a.priority)){\n // console.debug(`Resolving tenant ${identifier} by ${resolver.constructor.name}`);\n var tenant = await firstValueFrom(resolver.getTenantByIdentifier(identifier));\n if(tenant){\n tenant.resolvedBy = resolver.constructor.name;\n console.debug(`Tenant ${tenant.identifier} resolved by ${tenant.resolvedBy}`);\n if(!(resolver instanceof StorageResolver) || tenant.identifier != this.currentTenant?.identifier){\n this.storageResolver?.saveTenant(tenant);\n this.currentTenant = tenant;\n }\n return tenant;\n }\n }\n return null;\n }\n\n async getTenantInfo(): Promise<TenantInfo|null>{\n // :tenant/:module/:component\n var tenant = window.location.pathname.split('/')[1];\n this.requestTenantIdentifier = tenant;\n return (await this.getTenantByIdentifier(tenant))\n ?? this.storedTenant()\n ?? null\n ;\n }\n\n storedTenant(): TenantInfo|null|undefined{\n return this.storageResolver?.getCurrentTenant();\n }\n\n isMatched(): boolean{\n return this.currentTenant?.identifier == this.requestTenantIdentifier;\n }\n}\n","import {ɵisPromise as isPromise} from '@angular/core';\nimport {from, isObservable, Observable, of} from 'rxjs';\n\n\nexport function wrapIntoObservable<T>(value: T|Promise<T>|Observable<T>): Observable<T> {\n if (isObservable(value)) {\n return value;\n }\n \n if (isPromise(value)) {\n // Use `Promise.resolve()` to wrap promise-like instances.\n // Required ie when a Resolver returns a AngularJS `$q` promise to correctly trigger the\n // change detection.\n return from(Promise.resolve(value));\n }\n \n return of(value);\n }\n","\nimport { Injector, Type, createNgModule } from '@angular/core';\nimport { wrapIntoObservable} from './utils';\nimport { MENUS, MenuItem, Menus, CanDisplay } from './menu-item';\nimport { map } from 'rxjs/operators';\nimport { Observable, of, firstValueFrom } from 'rxjs';\nimport { ROUTES, Route } from '@angular/router';\n\nexport interface DefaultExport<T> {\n default: T;\n}\n\nexport async function loadChildren(menu: MenuItem, parentInjector: Injector, \n tenant: string|null|undefined): Promise<void>\n{\n if(menu.loaded){\n menu.injectTenant(tenant);\n return;\n }\n // console.debug(\"loadChildren\", menu.rawRouterLink);\n if(!hasChildren(menu)){\n return;\n }\n await loadChildrenInternal(menu, parentInjector, tenant)\n .then(children => {\n if(children!=null){\n console.debug(\"loadedChildren\", menu.rawRouterLink, children.map(c => c.rawRouterLink));\n menu.children = children;\n menu.injectTenant(tenant);\n }\n menu.loaded = true;\n })\n ;\n}\n\nasync function loadChildrenInternal(menu: MenuItem, parentInjector: Injector, tenant: string|null|undefined)\n: Promise<MenuItem[]>{\n \n var result: MenuItem[] = [];\n var children = await firstValueFrom(getChildren(menu, parentInjector, tenant));\n for(let child of children){\n if(hasChildren(child)){\n var sub = await loadChildrenInternal(child, parentInjector, tenant);\n if(sub.length > 0){\n result = result.concat(sub);\n }\n }else{\n result.push(child);\n }\n }\n \n return result.map(child => {\n child.rawRouterLink = menu.replaceChildRouterLink && menu.rawRouterLink ?\n ('/' + menu.rawRouterLink.trimSlash() + '/' + child.rawRouterLink.trimSlash()).trimEndSlash()\n : '/'+child.rawRouterLink.trimSlash();\n return child;\n });\n}\n\nfunction hasChildren(menu: MenuItem): boolean{\n return !((menu.children == null || menu.children.length==0) && !menu.loadChildren);\n}\n\nfunction getChildren(menu:MenuItem, parentInjector: Injector, tenant: string|null|undefined) \n : Observable<MenuItem[]>{\n if(menu.loadChildren){\n return wrapIntoObservable(menu.loadChildren())\n .pipe(\n map(t => loadMenus(t, parentInjector))\n );\n }else{\n return of(menu.children.filter(m => filterMenu(m, parentInjector)));\n }\n}\n\nfunction loadMenus(menusOrModule: Type<unknown>|Menus, parentInjector: Injector): MenuItem[] {\n \n if(Array.isArray(menusOrModule)){\n return menusOrModule.map(menu => new MenuItem(menu));\n }\n const module = createNgModule(menusOrModule, parentInjector);\n const injector = module.injector;\n const menus = injector.get(MENUS, [], {optional: true, self: true}).flat();\n const routes = injector.get(ROUTES, [], {optional: true, self: true});\n var routeMenus = mapRouteMenu(routes);\n // console.debug(\"loadMenus\", menus, routeMenus);\n return menus.map(menu => new MenuItem(menu)).concat(routeMenus)\n .filter(m => filterMenu(m, injector));\n}\n\nfunction filterMenu(menu: MenuItem, injector: Injector): boolean{\n\n if(menu.canDisplay instanceof Boolean){\n return menu.canDisplay as boolean;\n }\n const canDisplays = getCanDisplays(menu.canDisplay);\n\n return (canDisplays.length === 0 || canDisplays.every(\n (c: any) => {\n if(c instanceof Type){\n const service = injector.get<CanDisplay>(c as Type<CanDisplay>);\n return service.canDisplay();\n }else if(c instanceof Function){\n return c();\n }\n return true;\n }\n ))\n}\n\nfunction getCanDisplays(canDisplay: boolean|any[]): Array<any>{\n if(canDisplay instanceof Boolean){\n return [];\n }\n return Array.isArray(canDisplay) ? canDisplay : [];\n}\n\nexport function mapRouteMenu(routes: Route[][]): MenuItem[]{\n return routes\n .map(route => route.filter(isMenu).map(r => {\n if(!r.data){\n r.data = {};\n }\n return MenuItem.fromRoute(r);\n })\n ).flatMap(m => m.map(r => r!));\n}\n\nexport function isMenu(route: Route): boolean{\n return route.data && (route.data['menuDisplay'] || route.data['menuWrapper']);\n}\n","import { InjectionToken } from '@angular/core';\nimport { Route } from '@angular/router';\nimport { isMenu } from './menu-loader';\n\nexport class MenuItem {\n id: string = \"\";\n label: string = \"\";\n routerLink: string = \"\";\n rawRouterLink: string;\n icon: string = \"\";\n order: number = 0;\n children: MenuItem[];\n loadChildren?: Function;\n replaceChildRouterLink: boolean;\n loaded: boolean = false;\n canDisplay: any[] | boolean;\n \n constructor(menu: Menu){\n this.id = menu.id;\n this.label = menu.label;\n this.routerLink = menu.routerLink;\n this.icon = menu.icon;\n this.order = menu.order??0;\n this.children = menu.children?.map(m => new MenuItem(m))?? [];\n this.loadChildren = menu.loadChildren;\n this.replaceChildRouterLink = menu.replaceChildRouterLink ?? true;\n this.loaded = false;\n this.rawRouterLink = menu.routerLink;\n this.canDisplay = menu.canDisplay??[];\n }\n\n static fromRoute(route: Route): MenuItem{\n var menu = new MenuItem({\n id: route.path ?? '',\n label: route.data!['menuTitle']??route.title??route.path??'',\n routerLink: route.path??'',\n icon: route.data!['menuIcon']??'',\n order: route.data!['menuOrder']??0,\n children: route.children?.filter(isMenu).map(r => MenuItem.fromRoute(r))??[],\n loadChildren: route.loadChildren,\n replaceChildRouterLink: true,\n canDisplay: (route.data!['menuDisplay'] as boolean | any[])\n });\n return menu;\n }\n\n hasChildren(): boolean{\n return this.children.length > 0;\n }\n\n injectTenant(tenant: string|null|undefined){\n this.children?.forEach(item => {\n if(item.hasChildren()){\n item.injectTenant(tenant);\n }else{\n item.routerLink = item.rawRouterLink.injectTenant(tenant);\n }\n });\n this.routerLink = this.rawRouterLink.injectTenant(tenant);\n }\n}\n\nexport interface Menu {\n id: string,\n label: string,\n routerLink: string,\n icon: string,\n order?: number,\n children?: Menus,\n loadChildren?: any,\n replaceChildRouterLink?: boolean,\n canDisplay?: any[] | boolean\n}\n\nexport type Menus = Menu[];\n\nexport const MENUS = new InjectionToken<Menus[]>('MENUS');\n\nexport interface CanDisplay{\n canDisplay(): boolean;\n}","import { Injectable, Injector, inject } from '@angular/core';\nimport { MENUS, MenuItem } from './menu-item';\nimport { Observable, of } from 'rxjs';\nimport { map, mergeMap } from 'rxjs/operators';\nimport { loadChildren, mapRouteMenu } from './menu-loader';\nimport { TenantService } from '../tenant/tenant.service';\nimport { ROUTES, Route } from '@angular/router';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class MenuService {\n routes: Route[][] = [];\n constructor(private injector: Injector, private tenantService: TenantService) { \n this.routes = inject(ROUTES, {optional: true})??[];\n }\n\n getMenu():Observable<MenuItem[]>{\n var menus = this.injector.get(MENUS, [], {optional: true, self: true}).flat();\n var routeMenus = mapRouteMenu(this.routes);\n // console.debug(\"getMenu\", menus, routeMenus, this.routes);\n return of(menus)\n .pipe(\n map(menus => menus.map(m => new MenuItem(m))),\n map(async menus => {\n var tenant = await this.tenantService.getTenantIdentifier();\n let menuItems = [];\n for(let menu of menus.concat(routeMenus)){\n await loadChildren(menu, this.injector, tenant);\n menuItems.push(menu);\n }\n return menuItems;\n }),\n mergeMap(menus => menus),\n map(menus => menus.sort((a,b) => (a.order ?? 0) - (b.order ?? 0)))\n );\n }\n\n}\n","import { ModuleWithProviders, NgModule } from '@angular/core';\nimport { MenuService } from './menu.service';\nimport { MENUS, Menus } from './menu-item';\n\n@NgModule({\n declarations: [\n\n ],\n imports: [\n \n ],\n exports: [\n\n ]\n})\nexport class MenuModule {\n\n /**\n * Creates and configures a module with all the menu providers.\n * Optionally sets up an application listener to perform an initial navigation.\n *\n * When registering the NgModule at the root, import as follows:\n *\n * ```\n * @NgModule({\n * imports: [MenuModule.forRoot(MENUS)]\n * })\n * class MyNgModule {}\n * ```\n *\n * @param menus An array of `Route` objects that define the navigation paths for the application.\n * @return The new `NgModule`.\n *\n */\n public static forRoot(menus: Menus): ModuleWithProviders<MenuModule> {\n \n return {\n ngModule: MenuModule,\n providers: [\n MenuService,\n {\n provide: MENUS,\n multi: true,\n useValue: menus\n }\n ]\n };\n }\n\n /**\n * Creates a module with all the menus, without creating a new Router service.\n * When registering for submodules and lazy-loaded submodules, create the NgModule as follows:\n *\n * ```\n * @NgModule({\n * imports: [MenuModule.forChild(MENUS)]\n * })\n * class MyNgModule {}\n * ```\n *\n * @param menus An array of `MenuItem` objects that define the navigation paths for the submodule.\n * @return The new NgModule.\n *\n */\n public static forChild(menus: Menus): ModuleWithProviders<MenuModule> {\n return {\n ngModule: MenuModule,\n providers: [{provide: MENUS, multi: true, useValue: menus}],\n }\n }\n \n}","import { ROUTES, Routes } from \"@angular/router\";\nimport { ModuleWithProviders, Type, createNgModule } from \"@angular/core\";\n\nexport function loadChildrenRoutes(menusOrModule: ModuleWithProviders<any>): Routes {\n \n const module = createNgModule(menusOrModule.ngModule);\n const injector = module.injector;\n const menus = injector.get(ROUTES, [], {optional: true, self: true}).flat();\n return menus;\n}","export { };\ndeclare global {\n interface String {\n trimStartSlash(): string;\n trimEndSlash(): string;\n trimSlash(): string;\n injectTenant(tenant: string|null|undefined): string;\n }\n}\nString.prototype.trimStartSlash = function (): string{\n return this.replace(/^[\\/]+/, '');\n}\nString.prototype.trimEndSlash = function (): string{\n return this.replace(/[\\/]+$/, '');\n}\nString.prototype.trimSlash = function (): string{\n return this.trimStartSlash().trimEndSlash();\n}\nString.prototype.injectTenant = function (tenant: string|null|undefined): string{\n return '/' + this.replace(':tenant', tenant??'').trimStartSlash();\n}\n","import { MatDialog, MatDialogRef } from '@angular/material/dialog';\nimport { Directive } from '@angular/core';\n\n@Directive()\nexport abstract class AsyncDialog<ComponentType, DataType, ReturnType = unknown> {\n constructor(protected matDialog: MatDialog) {\n }\n\n abstract open(data: DataType): Promise<MatDialogRef<ComponentType, ReturnType>>;\n}","import { HttpContext, HttpContextToken } from '@angular/common/http';\n\n/**\n * Operation identifier that groups all HTTP attempts belonging to one logical\n * state-changing operation. Requests carrying the same operation id reuse the\n * same `Idempotency-Key` (across double-clicks and retries); a `null` value\n * means the request is not opted into idempotency.\n */\nexport const IDEMPOTENCY_OPERATION = new HttpContextToken<string | null>(() => null);\n\n/**\n * Optional client-side retry horizon (in milliseconds) that bounds how long a\n * key may be reused, mirroring the backend retention window. Past this age the\n * request is surfaced as an expired condition rather than silently treated as new.\n */\nexport const IDEMPOTENCY_MAX_AGE_MS = new HttpContextToken<number | null>(() => null);\n\n/**\n * Build (or extend) an {@link HttpContext} that opts a request into idempotency\n * for the given logical operation.\n *\n * @example\n * this.http.post('/orders', body, { context: withIdempotency('create-order-42') });\n */\nexport function withIdempotency(\n operationId: string,\n maxAgeMs?: number,\n context: HttpContext = new HttpContext(),\n): HttpContext {\n context.set(IDEMPOTENCY_OPERATION, operationId);\n if (maxAgeMs != null) {\n context.set(IDEMPOTENCY_MAX_AGE_MS, maxAgeMs);\n }\n return context;\n}\n","/**\n * Raised when the backend rejects a request because the same `Idempotency-Key`\n * was reused with a materially different payload (HTTP 422).\n */\nexport class IdempotencyConflictError extends Error {\n constructor(\n public readonly operationId: string,\n message = 'Idempotency key conflict: the same key was reused with a different payload.',\n ) {\n super(message);\n this.name = 'IdempotencyConflictError';\n }\n}\n\n/**\n * Raised when an endpoint requires an `Idempotency-Key` but none was supplied\n * (HTTP 400). Should not occur in normal client flow because the interceptor\n * always attaches a key to opted-in requests.\n */\nexport class IdempotencyKeyRequiredError extends Error {\n constructor(message = 'Idempotency-Key header is required for this request.') {\n super(message);\n this.name = 'IdempotencyKeyRequiredError';\n }\n}\n\n/**\n * Raised when a key has exceeded its client-side retry horizon and can no longer\n * be safely reused for the same operation.\n */\nexport class IdempotencyExpiredError extends Error {\n constructor(\n public readonly operationId: string,\n message = 'Idempotency key expired; the operation can no longer be safely retried with the same key.',\n ) {\n super(message);\n this.name = 'IdempotencyExpiredError';\n }\n}\n","import { HttpErrorResponse } from '@angular/common/http';\n\n/**\n * Classification of a backend response with respect to idempotency handling.\n */\nexport type IdempotencyOutcome = 'in-progress' | 'conflict' | 'required' | 'other';\n\n/**\n * Classify an {@link HttpErrorResponse} against the backend idempotency contract\n * (see the Juice backend `011-idempotency-key-api` feature):\n * - `409` → operation is still in progress (retry after backoff)\n * - `422` → key reused with a different payload (conflict)\n * - `400` with an idempotency-key ProblemDetails title → key required\n * - anything else → not an idempotency signal\n */\nexport function classifyError(error: HttpErrorResponse): IdempotencyOutcome {\n switch (error.status) {\n case 409:\n return 'in-progress';\n case 422:\n return 'conflict';\n case 400: {\n const title = (error.error && (error.error.title as string)) || '';\n return /idempotency[-\\s]?key/i.test(title) ? 'required' : 'other';\n }\n default:\n return 'other';\n }\n}\n","import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';\nimport { TenantService } from '../../tenant/tenant.service';\n\n/**\n * Optional provider of a user-scoped identifier (e.g. the authenticated subject)\n * folded into the idempotency key scope so keys are never reused across a user\n * switch. Kept as a token so `@juice-js/core` does not depend on `@juice-js/auth`\n * (which would introduce a circular library dependency). Applications with auth\n * provide `{ provide: IDEMPOTENCY_USER_CONTEXT, useValue: () => oauth.getIdentityClaims()?.sub ?? null }`.\n */\nexport const IDEMPOTENCY_USER_CONTEXT = new InjectionToken<() => string | null>('IDEMPOTENCY_USER_CONTEXT');\n\ninterface KeyEntry {\n key: string;\n scope: string;\n createdAt: number;\n inFlight: boolean;\n}\n\n/**\n * Generates, stores, and reuses a collision-resistant `Idempotency-Key` per\n * logical operation. The same operation id yields the same key across retries\n * and double-submits; distinct operations get distinct keys; and keys are scoped\n * to the current tenant/user so they never leak across a context switch.\n */\n@Injectable({ providedIn: 'root' })\nexport class IdempotencyKeyService {\n private readonly entries = new Map<string, KeyEntry>();\n\n constructor(\n @Optional() private readonly tenant: TenantService | null,\n @Optional() @Inject(IDEMPOTENCY_USER_CONTEXT) private readonly userContext: (() => string | null) | null,\n ) {}\n\n private currentScope(): string {\n const t = this.tenant?.currentTenant?.identifier ?? this.tenant?.requestTenantIdentifier ?? '';\n const u = this.userContext?.() ?? '';\n return `${t}|${u}`;\n }\n\n private newKey(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return crypto.randomUUID();\n }\n // Fallback RFC4122-style generator for environments without crypto.randomUUID.\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n }\n\n /**\n * Return the existing key for this operation, or generate a new one. If the\n * current tenant/user scope differs from the stored entry, a fresh key is\n * generated (FR-010).\n */\n getKey(operationId: string): string {\n const scope = this.currentScope();\n const existing = this.entries.get(operationId);\n if (existing && existing.scope === scope) {\n return existing.key;\n }\n const entry: KeyEntry = { key: this.newKey(), scope, createdAt: Date.now(), inFlight: false };\n this.entries.set(operationId, entry);\n return entry.key;\n }\n\n /** Forget the key for a completed (or abandoned) operation. */\n release(operationId: string): void {\n this.entries.delete(operationId);\n }\n\n /**\n * Whether the stored key for the operation has exceeded the given retry\n * horizon. Returns `false` when no horizon is set or no key exists yet.\n */\n isExpired(operationId: string, maxAgeMs: number | null | undefined): boolean {\n if (maxAgeMs == null) {\n return false;\n }\n const entry = this.entries.get(operationId);\n if (!entry) {\n return false;\n }\n return Date.now() - entry.createdAt > maxAgeMs;\n }\n\n /**\n * UI-level double-submit guard (FR-009). Returns `false` if an operation is\n * already in flight, so callers can suppress a duplicate dispatch.\n */\n tryBeginInFlight(operationId: string): boolean {\n const scope = this.currentScope();\n const entry: KeyEntry =\n this.entries.get(operationId) ?? { key: this.newKey(), scope, createdAt: Date.now(), inFlight: false };\n if (entry.inFlight) {\n return false;\n }\n entry.inFlight = true;\n this.entries.set(operationId, entry);\n return true;\n }\n\n /** Clear the in-flight flag set by {@link tryBeginInFlight}. */\n endInFlight(operationId: string): void {\n const entry = this.entries.get(operationId);\n if (entry) {\n entry.inFlight = false;\n }\n }\n}\n","import {\n HttpErrorResponse,\n HttpEvent,\n HttpHandler,\n HttpInterceptor,\n HttpRequest,\n HttpResponse,\n} from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { Observable, catchError, finalize, retry, shareReplay, tap, throwError, timer } from 'rxjs';\nimport { IDEMPOTENCY_MAX_AGE_MS, IDEMPOTENCY_OPERATION } from './idempotency.context';\nimport {\n IdempotencyConflictError,\n IdempotencyExpiredError,\n IdempotencyKeyRequiredError,\n} from './idempotency.errors';\nimport { IdempotencyKeyService } from './idempotency-key.service';\nimport { classifyError } from './idempotency-response';\n\n/**\n * Attaches an `Idempotency-Key` header to opted-in state-changing requests and\n * interprets the backend idempotency responses:\n * - replayed success is passed through and the key released;\n * - `409` in-progress triggers a bounded backoff retry reusing the same key;\n * - `422` conflict and `400` required surface as typed errors without resubmission;\n * - keys past their retry horizon surface as an expired error.\n *\n * On top of the shared key, it de-duplicates concurrent dispatches of the same\n * operation (FR-009): while one attempt is in flight, a second subscription to\n * the same operation is coalesced onto the first in-flight response instead of\n * issuing a parallel request, so a double-click settles on a single outcome.\n *\n * Mirrors the `@juice-js/auth` `AuthInterceptor` idiom.\n */\n@Injectable()\nexport class IdempotencyInterceptor implements HttpInterceptor {\n private readonly maxInProgressRetries = 3;\n private readonly baseBackoffMs = 500;\n\n /**\n * Shared, in-flight response streams keyed by operation id. Present only while\n * an operation is being sent; cleared when it settles (success or error).\n */\n private readonly inFlight = new Map<string, Observable<HttpEvent<unknown>>>();\n\n constructor(private readonly keys: IdempotencyKeyService) {}\n\n private isUnsafe(method: string): boolean {\n const m = method.toUpperCase();\n return m === 'POST' || m === 'PUT' || m === 'PATCH' || m === 'DELETE';\n }\n\n intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {\n const operationId = req.context.get(IDEMPOTENCY_OPERATION);\n\n // Not opted in, or a safe/read-only request → pass through untouched (FR-004).\n if (!operationId || !this.isUnsafe(req.method)) {\n return next.handle(req);\n }\n\n const maxAgeMs = req.context.get(IDEMPOTENCY_MAX_AGE_MS);\n if (this.keys.isExpired(operationId, maxAgeMs)) {\n this.keys.release(operationId);\n return throwError(() => new IdempotencyExpiredError(operationId));\n }\n\n // FR-009: a duplicate dispatch while the operation is in flight rides the\n // existing response instead of firing a parallel request.\n const existing = this.inFlight.get(operationId);\n if (existing) {\n return existing;\n }\n\n const key = this.keys.getKey(operationId);\n const idempotentReq = req.clone({ headers: req.headers.set('Idempotency-Key', key) });\n\n const shared = next.handle(idempotentReq).pipe(\n retry({\n count: this.maxInProgressRetries,\n delay: (error, retryCount) => {\n // Only retry the in-progress signal; every other error propagates immediately.\n if (!(error instanceof HttpErrorResponse) || classifyError(error) !== 'in-progress') {\n throw error;\n }\n return timer(this.baseBackoffMs * Math.pow(2, retryCount - 1));\n },\n }),\n tap((event) => {\n if (event instanceof HttpResponse) {\n this.keys.release(operationId);\n }\n }),\n catchError((error: unknown) => {\n if (error instanceof HttpErrorResponse) {\n switch (classifyError(error)) {\n case 'conflict':\n this.keys.release(operationId);\n return throwError(() => new IdempotencyConflictError(operationId));\n case 'required':\n this.keys.release(operationId);\n return throwError(() => new IdempotencyKeyRequiredError());\n case 'in-progress':\n // Retries exhausted while still in progress — surface the original error,\n // keeping the key so a later manual retry can reuse it within retention.\n return throwError(() => error);\n default:\n return throwError(() => error);\n }\n }\n return throwError(() => error);\n }),\n // Drop the coalescing entry once the operation settles so the next dispatch\n // starts a fresh attempt. With refCount:false below this fires on terminal\n // success or error, not on a subscriber leaving mid-flight.\n finalize(() => this.inFlight.delete(operationId)),\n // Multicast the single attempt to every coalesced subscriber; refCount:false\n // keeps the request running even if the initial subscriber unsubscribes.\n shareReplay({ bufferSize: 1, refCount: false }),\n );\n\n this.inFlight.set(operationId, shared);\n return shared;\n }\n}\n","import { HTTP_INTERCEPTORS } from '@angular/common/http';\nimport { NgModule } from '@angular/core';\nimport { IdempotencyInterceptor } from './idempotency.interceptor';\n\n/**\n * Registers the {@link IdempotencyInterceptor} so opted-in state-changing\n * requests automatically carry an `Idempotency-Key` header.\n *\n * @example\n * imports: [IdempotencyModule]\n */\n@NgModule({\n providers: [\n { provide: HTTP_INTERCEPTORS, useClass: IdempotencyInterceptor, multi: true },\n ],\n})\nexport class IdempotencyModule {}\n","/*\n * Public API Surface of core\n */\n\nexport * from './lib/tenant/tenant.service';\nexport * from './lib/tenant/tenant.module';\nexport * from './lib/tenant/tenant-info';\nexport * from './lib/menu/menu.service';\nexport * from './lib/menu/menu.module';\nexport * from './lib/menu/menu-item';\nexport * from './lib/routing/utils';\nexport * from './lib/extensions/index';\nexport * from './lib/dialog/async-dialog.service';\nexport * from './lib/http/idempotency/idempotency.context';\nexport * from './lib/http/idempotency/idempotency.errors';\nexport * from './lib/http/idempotency/idempotency-response';\nexport * from './lib/http/idempotency/idempotency-key.service';\nexport * from './lib/http/idempotency/idempotency.interceptor';\nexport * from './lib/http/idempotency/idempotency.module';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.StorageResolver","isPromise","firstValueFrom","i1.TenantService","i1.IdempotencyKeyService"],"mappings":";;;;;;;;;AAIO,MAAM,eAAe,GAAG,IAAI,cAAc,CAA0B,iBAAiB,CAAC;MAKvE,qBAAqB,CAAA;AAH3C,IAAA,WAAA,GAAA;QAKE,IAAA,CAAA,QAAQ,GAAG,CAAC;AAEb,IAAA;8GAJqB,qBAAqB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAA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,CAAC,WAAW,EAAE,MAAM,CAAC;AACtC,QAAA,OAAO,MAAM;IACf;8GAvFW,sBAAsB,EAAA,IAAA,EAAA,CAAA,EAAA,KAAA,EAAAC,qBAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;kHAAtB,sBAAsB,EAAA,CAAA,CAAA;;2FAAtB,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBADlC;;;AC9BD;;;;;;AAMG;MAMU,iBAAiB,CAAA;8GAAjB,iBAAiB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;+GAAjB,iBAAiB,EAAA,CAAA,CAAA;AAAjB,IAAA,SAAA,IAAA,CAAA,IAAA,GAAA,EAAA,CAAA,mBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,iBAAiB,EAAA,SAAA,EAJjB;YACT,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,sBAAsB,EAAE,KAAK,EAAE,IAAI,EAAE;AAC9E,SAAA,EAAA,CAAA,CAAA;;2FAEU,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBAL7B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,SAAS,EAAE;wBACT,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,sBAAsB,EAAE,KAAK,EAAE,IAAI,EAAE;AAC9E,qBAAA;AACF,iBAAA;;;ACfD;;AAEG;;ACFH;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juice-js/core",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Provides a set of core services for building web applications (menu, tenant etc).",
5
5
  "author": "jack@creatorflow.io",
6
6
  "license": "MIT",
@@ -4,6 +4,7 @@ import { Observable } from 'rxjs/internal/Observable';
4
4
  import { Observable as Observable$1 } from 'rxjs';
5
5
  import { Route, Routes } from '@angular/router';
6
6
  import { MatDialog, MatDialogRef } from '@angular/material/dialog';
7
+ import { HttpContextToken, HttpContext, HttpErrorResponse, HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
7
8
 
8
9
  interface TenantInfo {
9
10
  identifier: string;
@@ -159,5 +160,155 @@ declare abstract class AsyncDialog<ComponentType, DataType, ReturnType = unknown
159
160
  static ɵdir: i0.ɵɵDirectiveDeclaration<AsyncDialog<any, any, any>, never, never, {}, {}, never, never, true, never>;
160
161
  }
161
162
 
162
- export { AsyncDialog, MENUS, MenuItem, MenuModule, MenuService, TenantModule, TenantService, loadChildrenRoutes };
163
- export type { CanDisplay, Menu, Menus, TenantInfo };
163
+ /**
164
+ * Operation identifier that groups all HTTP attempts belonging to one logical
165
+ * state-changing operation. Requests carrying the same operation id reuse the
166
+ * same `Idempotency-Key` (across double-clicks and retries); a `null` value
167
+ * means the request is not opted into idempotency.
168
+ */
169
+ declare const IDEMPOTENCY_OPERATION: HttpContextToken<string | null>;
170
+ /**
171
+ * Optional client-side retry horizon (in milliseconds) that bounds how long a
172
+ * key may be reused, mirroring the backend retention window. Past this age the
173
+ * request is surfaced as an expired condition rather than silently treated as new.
174
+ */
175
+ declare const IDEMPOTENCY_MAX_AGE_MS: HttpContextToken<number | null>;
176
+ /**
177
+ * Build (or extend) an {@link HttpContext} that opts a request into idempotency
178
+ * for the given logical operation.
179
+ *
180
+ * @example
181
+ * this.http.post('/orders', body, { context: withIdempotency('create-order-42') });
182
+ */
183
+ declare function withIdempotency(operationId: string, maxAgeMs?: number, context?: HttpContext): HttpContext;
184
+
185
+ /**
186
+ * Raised when the backend rejects a request because the same `Idempotency-Key`
187
+ * was reused with a materially different payload (HTTP 422).
188
+ */
189
+ declare class IdempotencyConflictError extends Error {
190
+ readonly operationId: string;
191
+ constructor(operationId: string, message?: string);
192
+ }
193
+ /**
194
+ * Raised when an endpoint requires an `Idempotency-Key` but none was supplied
195
+ * (HTTP 400). Should not occur in normal client flow because the interceptor
196
+ * always attaches a key to opted-in requests.
197
+ */
198
+ declare class IdempotencyKeyRequiredError extends Error {
199
+ constructor(message?: string);
200
+ }
201
+ /**
202
+ * Raised when a key has exceeded its client-side retry horizon and can no longer
203
+ * be safely reused for the same operation.
204
+ */
205
+ declare class IdempotencyExpiredError extends Error {
206
+ readonly operationId: string;
207
+ constructor(operationId: string, message?: string);
208
+ }
209
+
210
+ /**
211
+ * Classification of a backend response with respect to idempotency handling.
212
+ */
213
+ type IdempotencyOutcome = 'in-progress' | 'conflict' | 'required' | 'other';
214
+ /**
215
+ * Classify an {@link HttpErrorResponse} against the backend idempotency contract
216
+ * (see the Juice backend `011-idempotency-key-api` feature):
217
+ * - `409` → operation is still in progress (retry after backoff)
218
+ * - `422` → key reused with a different payload (conflict)
219
+ * - `400` with an idempotency-key ProblemDetails title → key required
220
+ * - anything else → not an idempotency signal
221
+ */
222
+ declare function classifyError(error: HttpErrorResponse): IdempotencyOutcome;
223
+
224
+ /**
225
+ * Optional provider of a user-scoped identifier (e.g. the authenticated subject)
226
+ * folded into the idempotency key scope so keys are never reused across a user
227
+ * switch. Kept as a token so `@juice-js/core` does not depend on `@juice-js/auth`
228
+ * (which would introduce a circular library dependency). Applications with auth
229
+ * provide `{ provide: IDEMPOTENCY_USER_CONTEXT, useValue: () => oauth.getIdentityClaims()?.sub ?? null }`.
230
+ */
231
+ declare const IDEMPOTENCY_USER_CONTEXT: InjectionToken<() => string | null>;
232
+ /**
233
+ * Generates, stores, and reuses a collision-resistant `Idempotency-Key` per
234
+ * logical operation. The same operation id yields the same key across retries
235
+ * and double-submits; distinct operations get distinct keys; and keys are scoped
236
+ * to the current tenant/user so they never leak across a context switch.
237
+ */
238
+ declare class IdempotencyKeyService {
239
+ private readonly tenant;
240
+ private readonly userContext;
241
+ private readonly entries;
242
+ constructor(tenant: TenantService | null, userContext: (() => string | null) | null);
243
+ private currentScope;
244
+ private newKey;
245
+ /**
246
+ * Return the existing key for this operation, or generate a new one. If the
247
+ * current tenant/user scope differs from the stored entry, a fresh key is
248
+ * generated (FR-010).
249
+ */
250
+ getKey(operationId: string): string;
251
+ /** Forget the key for a completed (or abandoned) operation. */
252
+ release(operationId: string): void;
253
+ /**
254
+ * Whether the stored key for the operation has exceeded the given retry
255
+ * horizon. Returns `false` when no horizon is set or no key exists yet.
256
+ */
257
+ isExpired(operationId: string, maxAgeMs: number | null | undefined): boolean;
258
+ /**
259
+ * UI-level double-submit guard (FR-009). Returns `false` if an operation is
260
+ * already in flight, so callers can suppress a duplicate dispatch.
261
+ */
262
+ tryBeginInFlight(operationId: string): boolean;
263
+ /** Clear the in-flight flag set by {@link tryBeginInFlight}. */
264
+ endInFlight(operationId: string): void;
265
+ static ɵfac: i0.ɵɵFactoryDeclaration<IdempotencyKeyService, [{ optional: true; }, { optional: true; }]>;
266
+ static ɵprov: i0.ɵɵInjectableDeclaration<IdempotencyKeyService>;
267
+ }
268
+
269
+ /**
270
+ * Attaches an `Idempotency-Key` header to opted-in state-changing requests and
271
+ * interprets the backend idempotency responses:
272
+ * - replayed success is passed through and the key released;
273
+ * - `409` in-progress triggers a bounded backoff retry reusing the same key;
274
+ * - `422` conflict and `400` required surface as typed errors without resubmission;
275
+ * - keys past their retry horizon surface as an expired error.
276
+ *
277
+ * On top of the shared key, it de-duplicates concurrent dispatches of the same
278
+ * operation (FR-009): while one attempt is in flight, a second subscription to
279
+ * the same operation is coalesced onto the first in-flight response instead of
280
+ * issuing a parallel request, so a double-click settles on a single outcome.
281
+ *
282
+ * Mirrors the `@juice-js/auth` `AuthInterceptor` idiom.
283
+ */
284
+ declare class IdempotencyInterceptor implements HttpInterceptor {
285
+ private readonly keys;
286
+ private readonly maxInProgressRetries;
287
+ private readonly baseBackoffMs;
288
+ /**
289
+ * Shared, in-flight response streams keyed by operation id. Present only while
290
+ * an operation is being sent; cleared when it settles (success or error).
291
+ */
292
+ private readonly inFlight;
293
+ constructor(keys: IdempotencyKeyService);
294
+ private isUnsafe;
295
+ intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable$1<HttpEvent<unknown>>;
296
+ static ɵfac: i0.ɵɵFactoryDeclaration<IdempotencyInterceptor, never>;
297
+ static ɵprov: i0.ɵɵInjectableDeclaration<IdempotencyInterceptor>;
298
+ }
299
+
300
+ /**
301
+ * Registers the {@link IdempotencyInterceptor} so opted-in state-changing
302
+ * requests automatically carry an `Idempotency-Key` header.
303
+ *
304
+ * @example
305
+ * imports: [IdempotencyModule]
306
+ */
307
+ declare class IdempotencyModule {
308
+ static ɵfac: i0.ɵɵFactoryDeclaration<IdempotencyModule, never>;
309
+ static ɵmod: i0.ɵɵNgModuleDeclaration<IdempotencyModule, never, never, never>;
310
+ static ɵinj: i0.ɵɵInjectorDeclaration<IdempotencyModule>;
311
+ }
312
+
313
+ export { AsyncDialog, IDEMPOTENCY_MAX_AGE_MS, IDEMPOTENCY_OPERATION, IDEMPOTENCY_USER_CONTEXT, IdempotencyConflictError, IdempotencyExpiredError, IdempotencyInterceptor, IdempotencyKeyRequiredError, IdempotencyKeyService, IdempotencyModule, MENUS, MenuItem, MenuModule, MenuService, TenantModule, TenantService, classifyError, loadChildrenRoutes, withIdempotency };
314
+ export type { CanDisplay, IdempotencyOutcome, Menu, Menus, TenantInfo };