@daffodil/external-router 0.78.0 → 0.80.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.
- package/README.md +116 -7
- package/config.d.ts +1 -10
- package/driver/in-memory/config.d.ts +1 -7
- package/driver/in-memory/in-memory.module.d.ts +2 -0
- package/driver/in-memory/provider.d.ts +6 -0
- package/driver/in-memory/public_api.d.ts +1 -0
- package/driver/interfaces/external-router-driver.interface.d.ts +2 -6
- package/driver/magento/2.4.3/magento.service.d.ts +2 -1
- package/driver/magento/2.4.3/provider.d.ts +5 -0
- package/driver/magento/2.4.3/public_api.d.ts +1 -0
- package/driver/magento/2.4.3/transforms/schema/category/category.d.ts +2 -0
- package/driver/magento/2.4.3/transforms/schema/clientify-url-path.d.ts +1 -0
- package/driver/magento/2.4.3/transforms/schema/product/base.d.ts +2 -0
- package/driver/magento/2.4.3/transforms/schema/product/bundle.d.ts +2 -0
- package/driver/magento/2.4.3/transforms/schema/product/configurable.d.ts +2 -0
- package/driver/magento/2.4.3/transforms/schema/product/product.d.ts +5 -0
- package/driver/magento/2.4.3/transforms/schema/product/simple.d.ts +2 -0
- package/driver/magento/2.4.3/transforms/schema/rescale-rating.d.ts +5 -0
- package/driver/magento/2.4.3/transforms/schema/transform-schema.d.ts +2 -0
- package/driver/magento/2.4.3/transforms/transform-client-urls.d.ts +2 -0
- package/driver/magento/model/category-route-product.d.ts +77 -0
- package/driver/magento/model/category-route.d.ts +41 -0
- package/driver/magento/model/product-route.d.ts +85 -0
- package/driver/magento/model/public_api.d.ts +2 -0
- package/driver/magento/model/routable.d.ts +14 -0
- package/driver/magento/model/route.d.ts +4 -34
- package/driver/public_api.d.ts +1 -1
- package/driver/testing/config.d.ts +3 -9
- package/driver/testing/provider.d.ts +6 -0
- package/driver/testing/public_api.d.ts +1 -0
- package/esm2022/config.mjs +8 -7
- package/esm2022/driver/in-memory/config.mjs +8 -6
- package/esm2022/driver/in-memory/in-memory.module.mjs +8 -15
- package/esm2022/driver/in-memory/provider.mjs +12 -0
- package/esm2022/driver/in-memory/public_api.mjs +2 -1
- package/esm2022/driver/interfaces/external-router-driver.interface.mjs +8 -3
- package/esm2022/driver/magento/2.4.1/magento.module.mjs +5 -12
- package/esm2022/driver/magento/2.4.2/magento.module.mjs +5 -12
- package/esm2022/driver/magento/2.4.3/graphql/queries/resolve.mjs +66 -2
- package/esm2022/driver/magento/2.4.3/magento.module.mjs +5 -12
- package/esm2022/driver/magento/2.4.3/magento.service.mjs +12 -6
- package/esm2022/driver/magento/2.4.3/provider.mjs +13 -0
- package/esm2022/driver/magento/2.4.3/public_api.mjs +2 -1
- package/esm2022/driver/magento/2.4.3/transforms/resolution-to-resolvable-url.mjs +7 -3
- package/esm2022/driver/magento/2.4.3/transforms/schema/category/category.mjs +15 -0
- package/esm2022/driver/magento/2.4.3/transforms/schema/clientify-url-path.mjs +2 -0
- package/esm2022/driver/magento/2.4.3/transforms/schema/product/base.mjs +16 -0
- package/esm2022/driver/magento/2.4.3/transforms/schema/product/bundle.mjs +11 -0
- package/esm2022/driver/magento/2.4.3/transforms/schema/product/configurable.mjs +11 -0
- package/esm2022/driver/magento/2.4.3/transforms/schema/product/product.mjs +20 -0
- package/esm2022/driver/magento/2.4.3/transforms/schema/product/simple.mjs +25 -0
- package/esm2022/driver/magento/2.4.3/transforms/schema/rescale-rating.mjs +6 -0
- package/esm2022/driver/magento/2.4.3/transforms/schema/transform-schema.mjs +13 -0
- package/esm2022/driver/magento/2.4.3/transforms/transform-client-urls.mjs +28 -0
- package/esm2022/driver/magento/model/category-route-product.mjs +2 -0
- package/esm2022/driver/magento/model/category-route.mjs +2 -0
- package/esm2022/driver/magento/model/product-route.mjs +2 -0
- package/esm2022/driver/magento/model/public_api.mjs +1 -1
- package/esm2022/driver/magento/model/routable.mjs +2 -0
- package/esm2022/driver/magento/model/route.mjs +1 -1
- package/esm2022/driver/public_api.mjs +2 -2
- package/esm2022/driver/testing/config.mjs +8 -6
- package/esm2022/driver/testing/provider.mjs +12 -0
- package/esm2022/driver/testing/public_api.mjs +2 -1
- package/esm2022/driver/testing/testing.module.mjs +5 -11
- package/esm2022/driver/testing/testing.service.mjs +13 -11
- package/esm2022/model/public_api.mjs +1 -1
- package/esm2022/model/route-data.mjs +1 -1
- package/esm2022/model/route-with-seo-data.mjs +1 -1
- package/esm2022/provide-external-router.mjs +6 -0
- package/esm2022/public_api.mjs +2 -10
- package/esm2022/routing/guard/external-matcher-type.guard.mjs +43 -0
- package/esm2022/routing/helper/convert-to-path.mjs +7 -0
- package/esm2022/routing/public_api.mjs +2 -2
- package/fesm2022/daffodil-external-router-driver-in-memory.mjs +22 -18
- package/fesm2022/daffodil-external-router-driver-in-memory.mjs.map +1 -1
- package/fesm2022/daffodil-external-router-driver-magento-2.4.1.mjs +4 -11
- package/fesm2022/daffodil-external-router-driver-magento-2.4.1.mjs.map +1 -1
- package/fesm2022/daffodil-external-router-driver-magento-2.4.2.mjs +4 -11
- package/fesm2022/daffodil-external-router-driver-magento-2.4.2.mjs.map +1 -1
- package/fesm2022/daffodil-external-router-driver-magento-2.4.3.mjs +228 -21
- package/fesm2022/daffodil-external-router-driver-magento-2.4.3.mjs.map +1 -1
- package/fesm2022/daffodil-external-router-driver-testing.mjs +31 -25
- package/fesm2022/daffodil-external-router-driver-testing.mjs.map +1 -1
- package/fesm2022/daffodil-external-router-driver.mjs +8 -3
- package/fesm2022/daffodil-external-router-driver.mjs.map +1 -1
- package/fesm2022/daffodil-external-router-routing.mjs +40 -66
- package/fesm2022/daffodil-external-router-routing.mjs.map +1 -1
- package/fesm2022/daffodil-external-router.mjs +10 -282
- package/fesm2022/daffodil-external-router.mjs.map +1 -1
- package/model/public_api.d.ts +2 -5
- package/model/route-data.d.ts +13 -0
- package/model/route-with-seo-data.d.ts +3 -4
- package/package.json +1 -1
- package/provide-external-router.d.ts +3 -0
- package/public_api.d.ts +1 -9
- package/routing/guard/external-matcher-type.guard.d.ts +10 -0
- package/routing/helper/convert-to-path.d.ts +7 -0
- package/routing/public_api.d.ts +1 -1
- package/errors/no-wildcard.d.ts +0 -9
- package/errors/unknown-type.d.ts +0 -9
- package/esm2022/errors/no-wildcard.mjs +0 -12
- package/esm2022/errors/unknown-type.mjs +0 -12
- package/esm2022/external-router.module.mjs +0 -31
- package/esm2022/model/insertion-strategy.type.mjs +0 -2
- package/esm2022/model/route-info.mjs +0 -2
- package/esm2022/model/route-with-data-path.mjs +0 -2
- package/esm2022/model/route-with-type.mjs +0 -2
- package/esm2022/model/route-without-path.mjs +0 -2
- package/esm2022/model/type-route-pair.mjs +0 -2
- package/esm2022/router/router.service.mjs +0 -43
- package/esm2022/router/strategies/insert-data-path.mjs +0 -84
- package/esm2022/router/strategies/insert-route-before-wildcard.mjs +0 -17
- package/esm2022/router/url-matcher/data-path-matcher.mjs +0 -31
- package/esm2022/routing/guard/existence.guard.mjs +0 -77
- package/esm2022/token/type-resolvable-routes.token.mjs +0 -29
- package/esm2022/transform/resolved-route-to-route.mjs +0 -24
- package/esm2022/util/extract-daff-path-data.mjs +0 -9
- package/external-router.module.d.ts +0 -15
- package/model/insertion-strategy.type.d.ts +0 -8
- package/model/route-info.d.ts +0 -9
- package/model/route-with-data-path.d.ts +0 -14
- package/model/route-with-type.d.ts +0 -12
- package/model/route-without-path.d.ts +0 -7
- package/model/type-route-pair.d.ts +0 -26
- package/router/router.service.d.ts +0 -15
- package/router/strategies/insert-data-path.d.ts +0 -40
- package/router/strategies/insert-route-before-wildcard.d.ts +0 -6
- package/router/url-matcher/data-path-matcher.d.ts +0 -20
- package/routing/guard/existence.guard.d.ts +0 -22
- package/token/type-resolvable-routes.token.d.ts +0 -14
- package/transform/resolved-route-to-route.d.ts +0 -7
- package/util/extract-daff-path-data.d.ts +0 -6
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"daffodil-external-router-driver-testing.mjs","sources":["../../../libs/external-router/driver/testing/src/config.ts","../../../libs/external-router/driver/testing/src/testing.service.ts","../../../libs/external-router/driver/testing/src/testing.module.ts","../../../libs/external-router/driver/testing/src/public_api.ts","../../../libs/external-router/driver/testing/src/daffodil-external-router-driver-testing.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"file":"daffodil-external-router-driver-testing.mjs","sources":["../../../libs/external-router/driver/testing/src/config.ts","../../../libs/external-router/driver/testing/src/testing.service.ts","../../../libs/external-router/driver/testing/src/testing.module.ts","../../../libs/external-router/driver/testing/src/provider.ts","../../../libs/external-router/driver/testing/src/public_api.ts","../../../libs/external-router/driver/testing/src/daffodil-external-router-driver-testing.ts"],"sourcesContent":["import { createConfigInjectionToken } from '@daffodil/core';\nimport {\n DaffExternallyResolvableUrl,\n DaffExternalRouteType,\n} from '@daffodil/external-router';\n\n/**\n * The configuration for the testing driver. It is a dictionary of \"url\": \"type\",\n * pairs, where the URL is a URL-safe routeable path, e.g. \"sweatshirts\" or \"t-shirts\"\n * and the type is a known type to your application, e.g. \"CATEGORY\".\n */\nexport interface DaffExternalRouterDriverTestingConfig {\n [url: string]: DaffExternalRouteType | DaffExternallyResolvableUrl;\n}\n\nexport const {\n /**\n * The token used by Daffodil to hold the driver's configuration.\n *\n * @docs-private\n */\n token: DAFF_EXTERNAL_ROUTER_DRIVER_TESTING_CONFIG,\n /**\n * Provider function for {@link DAFF_EXTERNAL_ROUTER_DRIVER_TESTING_CONFIG}.\n */\n provider: provideDaffExternalRouterDriverTestingConfig,\n} = createConfigInjectionToken<DaffExternalRouterDriverTestingConfig>(({}), 'DAFF_EXTERNAL_ROUTER_DRIVER_TESTING_CONFIG');\n","import {\n Injectable,\n Inject,\n} from '@angular/core';\nimport { faker } from '@faker-js/faker/locale/en_US';\nimport {\n Observable,\n of,\n} from 'rxjs';\n\nimport {\n daffUriTruncateLeadingSlash,\n daffUriTruncateQueryFragment,\n} from '@daffodil/core/routing';\nimport { DaffExternallyResolvableUrl } from '@daffodil/external-router';\nimport {\n DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION,\n DaffExternalRouterDriverInterface,\n} from '@daffodil/external-router/driver';\n\nimport {\n DaffExternalRouterDriverTestingConfig,\n DAFF_EXTERNAL_ROUTER_DRIVER_TESTING_CONFIG,\n} from './config';\n\n/**\n * The DaffExternalRouterTestingDriver is responsible for translating an\n * arbitrary URI into a DaffExternallyResolvableUrl in testing environments.\n *\n * @inheritdoc\n *\n * @see {@link DaffExternalRouterTestingDriver}\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffExternalRouterTestingDriver\nimplements DaffExternalRouterDriverInterface {\n constructor(\n @Inject(DAFF_EXTERNAL_ROUTER_DRIVER_TESTING_CONFIG)\n private testingConfiguration: DaffExternalRouterDriverTestingConfig = {},\n ) {}\n\n resolve(url: string): Observable<DaffExternallyResolvableUrl> {\n const truncatedUrl = daffUriTruncateLeadingSlash(daffUriTruncateQueryFragment(url));\n\n if (!this.testingConfiguration[truncatedUrl]) {\n return of(DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION);\n }\n\n if((typeof this.testingConfiguration[truncatedUrl]) === 'string') {\n return of({\n id: faker.datatype.uuid(),\n url: truncatedUrl,\n type: <string>this.testingConfiguration[truncatedUrl],\n code: 200,\n });\n }\n\n return of(<DaffExternallyResolvableUrl>this.testingConfiguration[truncatedUrl]);\n }\n}\n","import { CommonModule } from '@angular/common';\nimport {\n NgModule,\n ModuleWithProviders,\n} from '@angular/core';\n\nimport { provideDaffExternalRouterDriver } from '@daffodil/external-router/driver';\n\nimport {\n DaffExternalRouterDriverTestingConfig,\n provideDaffExternalRouterDriverTestingConfig,\n} from './config';\nimport { DaffExternalRouterTestingDriver } from './testing.service';\n\n/**\n * The `DaffExternalRouterDriverTestingModule` is an importable NgModule that can\n * be used to configure the {@link DaffExternalRouterTestingDriver}.\n */\n@NgModule({\n declarations: [],\n imports: [CommonModule],\n})\nexport class DaffExternalRouterDriverTestingModule {\n static forRoot(\n config: DaffExternalRouterDriverTestingConfig,\n ): ModuleWithProviders<DaffExternalRouterDriverTestingModule> {\n return {\n ngModule: DaffExternalRouterDriverTestingModule,\n providers: [\n provideDaffExternalRouterDriver(DaffExternalRouterTestingDriver),\n provideDaffExternalRouterDriverTestingConfig(config),\n ],\n };\n }\n}\n","import {\n EnvironmentProviders,\n InjectionToken,\n makeEnvironmentProviders,\n} from '@angular/core';\n\nimport { provideDaffExternalRouterDriver } from '@daffodil/external-router/driver';\n\nimport {\n DaffExternalRouterDriverTestingConfig,\n provideDaffExternalRouterDriverTestingConfig,\n} from './config';\nimport { DaffExternalRouterTestingDriver } from './testing.service';\n\n/**\n * Provides a testing implementation of {@link DaffExternalRouterDriver}\n */\nexport const provideDaffExternalRouterTestingDriver = (config:\n DaffExternalRouterDriverTestingConfig | InjectionToken<DaffExternalRouterDriverTestingConfig>,\n): EnvironmentProviders => makeEnvironmentProviders([\n provideDaffExternalRouterDriver(DaffExternalRouterTestingDriver),\n provideDaffExternalRouterDriverTestingConfig(config),\n]);\n","/*\n * Public API Surface of @daffodil/external-router/driver/testing\n */\n\nexport { DaffExternalRouterTestingDriver } from './testing.service';\nexport { DaffExternalRouterDriverTestingModule } from './testing.module';\n\nexport { DaffExternalRouterDriverTestingConfig } from './config';\nexport { provideDaffExternalRouterTestingDriver } from './provider';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;AAeO,MAAM;AACX;;;;AAIG;AACH,KAAK,EAAE,0CAA0C;AACjD;;AAEG;AACH,QAAQ,EAAE,4CAA4C,GACvD,GAAG,0BAA0B,EAAyC,EAAE,GAAG,4CAA4C,CAAC;;ACDzH;;;;;;;AAOG;MAIU,+BAA+B,CAAA;AAE1C,IAAA,WAAA,CAEU,uBAA8D,EAAE,EAAA;QAAhE,IAAoB,CAAA,oBAAA,GAApB,oBAAoB,CAA4C;KACtE;AAEJ,IAAA,OAAO,CAAC,GAAW,EAAA;QACjB,MAAM,YAAY,GAAG,2BAA2B,CAAC,4BAA4B,CAAC,GAAG,CAAC,CAAC,CAAC;QAEpF,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
6
|
*/
|
6
|
-
|
7
|
+
token: DaffExternalRouterDriver,
|
8
|
+
/**
|
9
|
+
* Provider function for {@link DaffExternalRouterDriver}.
|
10
|
+
*/
|
11
|
+
provider: provideDaffExternalRouterDriver, } = createSingletonInjectionToken('DaffExternalRouterDriver');
|
7
12
|
|
8
13
|
/**
|
9
14
|
* When a driver fails to find a resolution, it should return a 404.
|
@@ -26,5 +31,5 @@ const DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION = {
|
|
26
31
|
* Generated bundle index. Do not edit.
|
27
32
|
*/
|
28
33
|
|
29
|
-
export { DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION, DaffExternalRouterDriver };
|
34
|
+
export { DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION, DaffExternalRouterDriver, provideDaffExternalRouterDriver };
|
30
35
|
//# sourceMappingURL=daffodil-external-router-driver.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"daffodil-external-router-driver.mjs","sources":["../../../libs/external-router/driver/src/interfaces/external-router-driver.interface.ts","../../../libs/external-router/driver/src/not-found-resolution.ts","../../../libs/external-router/driver/src/public_api.ts","../../../libs/external-router/driver/src/daffodil-external-router-driver.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"file":"daffodil-external-router-driver.mjs","sources":["../../../libs/external-router/driver/src/interfaces/external-router-driver.interface.ts","../../../libs/external-router/driver/src/not-found-resolution.ts","../../../libs/external-router/driver/src/public_api.ts","../../../libs/external-router/driver/src/daffodil-external-router-driver.ts"],"sourcesContent":["import { Observable } from 'rxjs';\n\nimport { createSingletonInjectionToken } from '@daffodil/core';\nimport { DaffExternallyResolvableUrl } from '@daffodil/external-router';\n\nexport const {\n /**\n * The token for the `@daffodil/external-router` driver.\n */\n token: DaffExternalRouterDriver,\n /**\n * Provider function for {@link DaffExternalRouterDriver}.\n */\n provider: provideDaffExternalRouterDriver,\n} = createSingletonInjectionToken<DaffExternalRouterDriverInterface>('DaffExternalRouterDriver');\n\n/**\n * The interface for a `@daffodil/external-router` driver.\n *\n * This driver is responsible for translating a URL into a Route consumable by\n * Daffodil.\n */\nexport interface DaffExternalRouterDriverInterface {\n /**\n * Resolves a URL with a platform.\n * Returns information about the type of URL.\n *\n * @param url The full URL path qualified with file extension and leading slash but without domain. i.e. /full/path/to/thing.html\n */\n resolve(url: string): Observable<DaffExternallyResolvableUrl>;\n}\n","import { DaffExternallyResolvableUrl } from '@daffodil/external-router';\n\n/**\n * When a driver fails to find a resolution, it should return a 404.\n * This const represents the standard \"Not Found\" resolution that a driver\n * should return. Drivers are not required to return this value, but may do so\n * if they would like.\n */\nexport const DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION: DaffExternallyResolvableUrl = {\n id: null,\n url: null,\n code: 404,\n type: null,\n};\n","/*\n * Public API Surface of @daffodil/external-router/driver\n */\n\nexport {\n DaffExternalRouterDriverInterface,\n DaffExternalRouterDriver,\n provideDaffExternalRouterDriver,\n} from './interfaces/external-router-driver.interface';\nexport { DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION } from './not-found-resolution';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAKa,MAAA;AACX;;AAEG;AACH,KAAK,EAAE,wBAAwB;AAC/B;;AAEG;AACH,QAAQ,EAAE,+BAA+B,GAC1C,GAAG,6BAA6B,CAAoC,0BAA0B;;ACZ/F;;;;;AAKG;AACU,MAAA,yCAAyC,GAAgC;AACpF,IAAA,EAAE,EAAE,IAAI;AACR,IAAA,GAAG,EAAE,IAAI;AACT,IAAA,IAAI,EAAE,GAAG;AACT,IAAA,IAAI,EAAE,IAAI;;;ACZZ;;AAEG;;ACFH;;AAEG;;;;"}
|
@@ -1,10 +1,6 @@
|
|
1
|
-
import
|
2
|
-
import {
|
3
|
-
import
|
4
|
-
import { of } from 'rxjs';
|
5
|
-
import { map, switchMap, catchError } from 'rxjs/operators';
|
6
|
-
import * as i3 from '@daffodil/core/routing';
|
7
|
-
import * as i1 from '@daffodil/external-router';
|
1
|
+
import { inject } from '@angular/core';
|
2
|
+
import { Router } from '@angular/router';
|
3
|
+
import { map, tap, catchError, of } from 'rxjs';
|
8
4
|
import { DAFF_EXTERNAL_ROUTER_CONFIG } from '@daffodil/external-router';
|
9
5
|
import { DaffExternalRouterDriver } from '@daffodil/external-router/driver';
|
10
6
|
import { DaffInheritableError } from '@daffodil/core';
|
@@ -53,6 +49,13 @@ class DaffExternalRouterTemporaryRedirectError extends DaffInheritableError {
|
|
53
49
|
}
|
54
50
|
}
|
55
51
|
|
52
|
+
/**
|
53
|
+
* Converts a UrlSegment into its complete Url.
|
54
|
+
*
|
55
|
+
* @docs-private
|
56
|
+
*/
|
57
|
+
const daffConvertToPath = (segments) => segments.map(seg => seg.path).join('/');
|
58
|
+
|
56
59
|
/**
|
57
60
|
* An error thrown when the platform performing url resolution fails.
|
58
61
|
*/
|
@@ -99,65 +102,36 @@ const processRedirects = (url) => {
|
|
99
102
|
};
|
100
103
|
|
101
104
|
/**
|
102
|
-
*
|
103
|
-
*
|
104
|
-
*
|
105
|
+
* A `canMatch` guard function that will resolve a route externally, allowing Angular to match it.
|
106
|
+
*
|
107
|
+
* Depending on the resolution result, the route's data will contain `daffSeoData` with supplemental search engine data
|
108
|
+
* about the route. The data on the route is cumulative. If other data properties are set, they will be merged alongside daffSeoData.
|
105
109
|
*/
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
}
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
// Handle "404"
|
132
|
-
catchError((error) => {
|
133
|
-
if (!(error instanceof DaffExternalRouterNotFoundError)) {
|
134
|
-
throw error;
|
135
|
-
}
|
136
|
-
return of(this.router.parseUrl(this.config.notFoundResolutionPath));
|
137
|
-
}),
|
138
|
-
//Otherwise something went horribly wrong and we need to bail out.
|
139
|
-
catchError((error) => {
|
140
|
-
//TODO(damienwebdev): Add a logging system.
|
141
|
-
//This log is intentional until we have a better logging system in place.
|
142
|
-
console.log(error);
|
143
|
-
return of(this.router.parseUrl(this.config.failedResolutionPath));
|
144
|
-
}));
|
145
|
-
}
|
146
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.2", ngImport: i0, type: DaffExternalRouterExistenceGuard, deps: [{ token: DaffExternalRouterDriver }, { token: i1.DaffExternalRouter }, { token: i2.Router }, { token: DAFF_EXTERNAL_ROUTER_CONFIG }, { token: i3.DaffRoutingUriNormalizer }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
147
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.2", ngImport: i0, type: DaffExternalRouterExistenceGuard, providedIn: 'root' }); }
|
148
|
-
}
|
149
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.2", ngImport: i0, type: DaffExternalRouterExistenceGuard, decorators: [{
|
150
|
-
type: Injectable,
|
151
|
-
args: [{
|
152
|
-
providedIn: 'root',
|
153
|
-
}]
|
154
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
155
|
-
type: Inject,
|
156
|
-
args: [DaffExternalRouterDriver]
|
157
|
-
}] }, { type: i1.DaffExternalRouter }, { type: i2.Router }, { type: undefined, decorators: [{
|
158
|
-
type: Inject,
|
159
|
-
args: [DAFF_EXTERNAL_ROUTER_CONFIG]
|
160
|
-
}] }, { type: i3.DaffRoutingUriNormalizer }] });
|
110
|
+
const daffExternalMatcherTypeGuard = (type) => (route, segments) => {
|
111
|
+
const router = inject(Router);
|
112
|
+
const config = inject(DAFF_EXTERNAL_ROUTER_CONFIG);
|
113
|
+
return inject(DaffExternalRouterDriver).resolve(daffConvertToPath(segments)).pipe(map(processErrors), map(processRedirects), map((r) => ({ result: r, isMatch: type === r.type })), tap((r) => {
|
114
|
+
if (r.isMatch) {
|
115
|
+
route.title = r.result.data?.title ?? route.data?.daffSeoData?.title ?? route.title;
|
116
|
+
route.data = { ...route.data, daffSeoData: r.result.data };
|
117
|
+
}
|
118
|
+
}), map((res) => res.isMatch), catchError(error => {
|
119
|
+
if (!(error instanceof DaffExternalRouterPermanentRedirectError) &&
|
120
|
+
!(error instanceof DaffExternalRouterTemporaryRedirectError)) {
|
121
|
+
throw error;
|
122
|
+
}
|
123
|
+
return of(router.parseUrl(error.redirectUrl));
|
124
|
+
}),
|
125
|
+
// Handle "404"
|
126
|
+
catchError((error) => {
|
127
|
+
if (!(error instanceof DaffExternalRouterNotFoundError)) {
|
128
|
+
throw error;
|
129
|
+
}
|
130
|
+
return of(false);
|
131
|
+
}),
|
132
|
+
//Otherwise something went horribly wrong and we need to bail out.
|
133
|
+
catchError((error) => of(router.parseUrl(config.failedResolutionPath))), catchError(() => of(false)));
|
134
|
+
};
|
161
135
|
|
162
136
|
/*
|
163
137
|
* Public API Surface of @daffodil/external-router/routing
|
@@ -167,5 +141,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.2", ngImpor
|
|
167
141
|
* Generated bundle index. Do not edit.
|
168
142
|
*/
|
169
143
|
|
170
|
-
export {
|
144
|
+
export { daffExternalMatcherTypeGuard };
|
171
145
|
//# sourceMappingURL=daffodil-external-router-routing.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"daffodil-external-router-routing.mjs","sources":["../../../libs/external-router/routing/src/errors/client-error.ts","../../../libs/external-router/routing/src/errors/not-found-error.ts","../../../libs/external-router/routing/src/errors/permanent-redirect.ts","../../../libs/external-router/routing/src/errors/temporary-redirect.ts","../../../libs/external-router/routing/src/errors/server-error.ts","../../../libs/external-router/routing/src/processors/process-errors.ts","../../../libs/external-router/routing/src/processors/process-redirect.ts","../../../libs/external-router/routing/src/guard/existence.guard.ts","../../../libs/external-router/routing/src/public_api.ts","../../../libs/external-router/routing/src/daffodil-external-router-routing.ts"],"sourcesContent":["import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\n/**\n * An error thrown when the driver encounters a 4xx error.\n */\nexport class DaffExternalRouterClientError extends DaffInheritableError\n implements DaffError {\n public readonly code: string = '4xx_CLIENT_ERROR';\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import { DaffError } from '@daffodil/core';\n\nimport { DaffExternalRouterClientError } from './client-error';\n\n/**\n * An error thrown when the driver determines that a given url is not resolvable.\n */\nexport class DaffExternalRouterNotFoundError extends DaffExternalRouterClientError\n implements DaffError {\n public readonly code: string = '404_NOT_FOUND';\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\n/**\n * An error thrown when the driver determines that the url needs to be routed somewhere\n * else permanently.\n */\nexport class DaffExternalRouterPermanentRedirectError extends DaffInheritableError\n implements DaffError {\n public readonly code: string = '302_PERMANENT_REDIRECT';\n\n constructor(public redirectUrl: string, message?: string) {\n super(message);\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\n/**\n * An error thrown when the driver needs a URI to be temporarily redirected\n * to another location.\n */\nexport class DaffExternalRouterTemporaryRedirectError extends DaffInheritableError\n implements DaffError {\n public readonly code: string = 'TEMPORARY_REDIRECT';\n\n constructor(public redirectUrl: string, message?: string) {\n super(message);\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\n/**\n * An error thrown when the platform performing url resolution fails.\n */\nexport class DaffExternalRouterServerError extends DaffInheritableError\n implements DaffError {\n public readonly code: string = '5xx_SERVER_ERROR';\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import { DaffExternallyResolvableUrl } from '@daffodil/external-router';\n\n\nimport { DaffExternalRouterClientError } from '../errors/client-error';\nimport { DaffExternalRouterNotFoundError } from '../errors/not-found-error';\nimport { DaffExternalRouterServerError } from '../errors/server-error';\n\n/**\n * Processes resolved URLs and throws the appropriate error so that External Router\n * can handle routing errors.\n */\nexport const processErrors = (url: DaffExternallyResolvableUrl): DaffExternallyResolvableUrl => {\n if(url.code === 404 ){\n throw new DaffExternalRouterNotFoundError();\n } else if(url.code >= 400 && url.code < 500) {\n throw new DaffExternalRouterClientError();\n } else if(url.code >= 500) {\n throw new DaffExternalRouterServerError();\n } else {\n return url;\n }\n};\n","import { DaffExternallyResolvableUrl } from '@daffodil/external-router';\n\nimport { DaffExternalRouterPermanentRedirectError } from '../errors/permanent-redirect';\nimport { DaffExternalRouterTemporaryRedirectError } from '../errors/temporary-redirect';\n\n/**\n * Processes resolvedUrls and throws the appropriate error so that External Router\n * can handle redirects.\n */\nexport const processRedirects = (url: DaffExternallyResolvableUrl): DaffExternallyResolvableUrl => {\n if(url.code === 301){\n throw new DaffExternalRouterPermanentRedirectError(url.url);\n } else if(url.code === 302) {\n throw new DaffExternalRouterTemporaryRedirectError(url.url);\n } else {\n return url;\n }\n};\n","import { isPlatformServer } from '@angular/common';\nimport {\n Injectable,\n Inject,\n PLATFORM_ID,\n} from '@angular/core';\nimport {\n ActivatedRouteSnapshot,\n Router,\n RouterStateSnapshot,\n UrlTree,\n} from '@angular/router';\nimport {\n Observable,\n of,\n} from 'rxjs';\nimport {\n catchError,\n map,\n switchMap,\n} from 'rxjs/operators';\n\nimport { DaffRoutingUriNormalizer } from '@daffodil/core/routing';\nimport {\n DaffExternalRouter,\n DaffExternalRouterConfiguration,\n DAFF_EXTERNAL_ROUTER_CONFIG,\n DaffExternallyResolvableUrl,\n} from '@daffodil/external-router';\nimport {\n DaffExternalRouterDriverInterface,\n DaffExternalRouterDriver,\n} from '@daffodil/external-router/driver';\n\nimport { DaffExternalRouterNotFoundError } from '../errors/not-found-error';\nimport { DaffExternalRouterPermanentRedirectError } from '../errors/permanent-redirect';\nimport { DaffExternalRouterTemporaryRedirectError } from '../errors/temporary-redirect';\nimport { processErrors } from '../processors/process-errors';\nimport { processRedirects } from '../processors/process-redirect';\n\n/**\n * The DaffExternalRouterExistenceGuard is responsible for guarding the wildcard route\n * of an Angular App and either navigating to a resolved route upon successful resolution\n * or navigating to the configured route upon a failed resolution.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffExternalRouterExistenceGuard {\n constructor(\n @Inject(DaffExternalRouterDriver)\n private driver: DaffExternalRouterDriverInterface,\n private externalRouter: DaffExternalRouter,\n private router: Router,\n @Inject(DAFF_EXTERNAL_ROUTER_CONFIG)\n private config: DaffExternalRouterConfiguration,\n private urlNormalizer: DaffRoutingUriNormalizer,\n ) { }\n\n canActivate(\n next: ActivatedRouteSnapshot,\n state: RouterStateSnapshot,\n ): Observable<UrlTree | boolean> {\n return this.driver.resolve(this.urlNormalizer.normalize(state.url)).pipe(\n map((resolvedRoute: DaffExternallyResolvableUrl) => processErrors(resolvedRoute)),\n switchMap(resolvedRoute => {\n this.externalRouter.add(resolvedRoute);\n return of(resolvedRoute);\n }),\n map((resolvedRoute: DaffExternallyResolvableUrl) => processRedirects(resolvedRoute)),\n // Note that we have to use state.url as we want to ensure that we keep any fragments or query strings.\n // When we succeed, redirect to the new route, as config has changed since we init'd.\n map(() => this.router.parseUrl(state.url)),\n // When we fail, we need to process errors as dictated by the error type.\n // Handle redirects\n catchError(error => {\n if (\n !(error instanceof DaffExternalRouterPermanentRedirectError) &&\n !(error instanceof DaffExternalRouterTemporaryRedirectError)) {\n throw error;\n }\n\n return of(this.router.parseUrl(error.redirectUrl));\n }),\n // Handle \"404\"\n catchError((error) => {\n if (!(error instanceof DaffExternalRouterNotFoundError)) {\n throw error;\n }\n\n return of(this.router.parseUrl(this.config.notFoundResolutionPath));\n }),\n\n //Otherwise something went horribly wrong and we need to bail out.\n catchError((error) => {\n //TODO(damienwebdev): Add a logging system.\n //This log is intentional until we have a better logging system in place.\n console.log(error);\n return of(this.router.parseUrl(this.config.failedResolutionPath));\n }),\n );\n }\n}\n","/*\n * Public API Surface of @daffodil/external-router/routing\n */\nexport { DaffExternalRouterExistenceGuard } from './guard/existence.guard';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;AAKA;;AAEG;AACG,MAAO,6BAA8B,SAAQ,oBAAoB,CAAA;AAIrE,IAAA,WAAA,CAAY,OAAgB,EAAA;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHD,IAAI,CAAA,IAAA,GAAW,kBAAkB,CAAC;KAIjD;AACF;;ACXD;;AAEG;AACG,MAAO,+BAAgC,SAAQ,6BAA6B,CAAA;AAIhF,IAAA,WAAA,CAAY,OAAgB,EAAA;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHD,IAAI,CAAA,IAAA,GAAW,eAAe,CAAC;KAI9C;AACF;;ACTD;;;AAGG;AACG,MAAO,wCAAyC,SAAQ,oBAAoB,CAAA;IAIhF,WAAmB,CAAA,WAAmB,EAAE,OAAgB,EAAA;QACtD,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,IAAW,CAAA,WAAA,GAAX,WAAW,CAAQ;QAFtB,IAAI,CAAA,IAAA,GAAW,wBAAwB,CAAC;KAIvD;AACF;;ACXD;;;AAGG;AACG,MAAO,wCAAyC,SAAQ,oBAAoB,CAAA;IAIhF,WAAmB,CAAA,WAAmB,EAAE,OAAgB,EAAA;QACtD,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,IAAW,CAAA,WAAA,GAAX,WAAW,CAAQ;QAFtB,IAAI,CAAA,IAAA,GAAW,oBAAoB,CAAC;KAInD;AACF;;ACXD;;AAEG;AACG,MAAO,6BAA8B,SAAQ,oBAAoB,CAAA;AAIrE,IAAA,WAAA,CAAY,OAAgB,EAAA;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHD,IAAI,CAAA,IAAA,GAAW,kBAAkB,CAAC;KAIjD;AACF;;ACRD;;;AAGG;AACI,MAAM,a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,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC;SACnE,CAAC,CACH,CAAC;KACH;iIArDU,gCAAgC,EAAA,IAAA,EAAA,CAAA,EAAA,KAAA,EAEjC,wBAAwB,EAAA,EAAA,EAAA,KAAA,EAAA,EAAA,CAAA,kBAAA,EAAA,EAAA,EAAA,KAAA,EAAA,EAAA,CAAA,MAAA,EAAA,EAAA,EAAA,KAAA,EAIxB,2BAA2B,EAAA,EAAA,EAAA,KAAA,EAAA,EAAA,CAAA,wBAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA,EAAA;AAN1B,uBAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,gCAAgC,cAF/B,MAAM,EAAA,CAAA,CAAA,EAAA;;2FAEP,gCAAgC,EAAA,UAAA,EAAA,CAAA;kBAH5C,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA,CAAA;;0BAGI,MAAM;2BAAC,wBAAwB,CAAA;;0BAI/B,MAAM;2BAAC,2BAA2B,CAAA;;;ACtDvC;;AAEG;;ACFH;;AAEG;;;;"}
|
1
|
+
{"version":3,"file":"daffodil-external-router-routing.mjs","sources":["../../../libs/external-router/routing/src/errors/client-error.ts","../../../libs/external-router/routing/src/errors/not-found-error.ts","../../../libs/external-router/routing/src/errors/permanent-redirect.ts","../../../libs/external-router/routing/src/errors/temporary-redirect.ts","../../../libs/external-router/routing/src/helper/convert-to-path.ts","../../../libs/external-router/routing/src/errors/server-error.ts","../../../libs/external-router/routing/src/processors/process-errors.ts","../../../libs/external-router/routing/src/processors/process-redirect.ts","../../../libs/external-router/routing/src/guard/external-matcher-type.guard.ts","../../../libs/external-router/routing/src/public_api.ts","../../../libs/external-router/routing/src/daffodil-external-router-routing.ts"],"sourcesContent":["import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\n/**\n * An error thrown when the driver encounters a 4xx error.\n */\nexport class DaffExternalRouterClientError extends DaffInheritableError\n implements DaffError {\n public readonly code: string = '4xx_CLIENT_ERROR';\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import { DaffError } from '@daffodil/core';\n\nimport { DaffExternalRouterClientError } from './client-error';\n\n/**\n * An error thrown when the driver determines that a given url is not resolvable.\n */\nexport class DaffExternalRouterNotFoundError extends DaffExternalRouterClientError\n implements DaffError {\n public readonly code: string = '404_NOT_FOUND';\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\n/**\n * An error thrown when the driver determines that the url needs to be routed somewhere\n * else permanently.\n */\nexport class DaffExternalRouterPermanentRedirectError extends DaffInheritableError\n implements DaffError {\n public readonly code: string = '302_PERMANENT_REDIRECT';\n\n constructor(public redirectUrl: string, message?: string) {\n super(message);\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\n/**\n * An error thrown when the driver needs a URI to be temporarily redirected\n * to another location.\n */\nexport class DaffExternalRouterTemporaryRedirectError extends DaffInheritableError\n implements DaffError {\n public readonly code: string = 'TEMPORARY_REDIRECT';\n\n constructor(public redirectUrl: string, message?: string) {\n super(message);\n }\n}\n","import { UrlSegment } from '@angular/router';\n\n/**\n * Converts a UrlSegment into its complete Url.\n *\n * @docs-private\n */\nexport const daffConvertToPath = (segments: UrlSegment[]) => segments.map(seg => seg.path).join('/');\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\n/**\n * An error thrown when the platform performing url resolution fails.\n */\nexport class DaffExternalRouterServerError extends DaffInheritableError\n implements DaffError {\n public readonly code: string = '5xx_SERVER_ERROR';\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import { DaffExternallyResolvableUrl } from '@daffodil/external-router';\n\n\nimport { DaffExternalRouterClientError } from '../errors/client-error';\nimport { DaffExternalRouterNotFoundError } from '../errors/not-found-error';\nimport { DaffExternalRouterServerError } from '../errors/server-error';\n\n/**\n * Processes resolved URLs and throws the appropriate error so that External Router\n * can handle routing errors.\n */\nexport const processErrors = (url: DaffExternallyResolvableUrl): DaffExternallyResolvableUrl => {\n if(url.code === 404 ){\n throw new DaffExternalRouterNotFoundError();\n } else if(url.code >= 400 && url.code < 500) {\n throw new DaffExternalRouterClientError();\n } else if(url.code >= 500) {\n throw new DaffExternalRouterServerError();\n } else {\n return url;\n }\n};\n","import { DaffExternallyResolvableUrl } from '@daffodil/external-router';\n\nimport { DaffExternalRouterPermanentRedirectError } from '../errors/permanent-redirect';\nimport { DaffExternalRouterTemporaryRedirectError } from '../errors/temporary-redirect';\n\n/**\n * Processes resolvedUrls and throws the appropriate error so that External Router\n * can handle redirects.\n */\nexport const processRedirects = (url: DaffExternallyResolvableUrl): DaffExternallyResolvableUrl => {\n if(url.code === 301){\n throw new DaffExternalRouterPermanentRedirectError(url.url);\n } else if(url.code === 302) {\n throw new DaffExternalRouterTemporaryRedirectError(url.url);\n } else {\n return url;\n }\n};\n","import { inject } from '@angular/core';\nimport {\n CanMatchFn,\n Router,\n UrlSegment,\n UrlTree,\n} from '@angular/router';\nimport {\n Observable,\n catchError,\n map,\n of,\n tap,\n} from 'rxjs';\n\nimport {\n DAFF_EXTERNAL_ROUTER_CONFIG,\n DaffExternalRouterConfiguration,\n DaffExternallyResolvableUrl,\n DaffRouteWithSeoData,\n} from '@daffodil/external-router';\nimport { DaffExternalRouterDriver } from '@daffodil/external-router/driver';\n\nimport { DaffExternalRouterNotFoundError } from '../errors/not-found-error';\nimport { DaffExternalRouterPermanentRedirectError } from '../errors/permanent-redirect';\nimport { DaffExternalRouterTemporaryRedirectError } from '../errors/temporary-redirect';\nimport { daffConvertToPath } from '../helper/convert-to-path';\nimport { processErrors } from '../processors/process-errors';\nimport { processRedirects } from '../processors/process-redirect';\n\n/**\n * A `canMatch` guard function that will resolve a route externally, allowing Angular to match it.\n *\n * Depending on the resolution result, the route's data will contain `daffSeoData` with supplemental search engine data\n * about the route. The data on the route is cumulative. If other data properties are set, they will be merged alongside daffSeoData.\n */\nexport const daffExternalMatcherTypeGuard = (type: string) => (route: DaffRouteWithSeoData, segments: Array<UrlSegment>): Observable<boolean | UrlTree> => {\n const router = inject(Router);\n const config: DaffExternalRouterConfiguration = inject(DAFF_EXTERNAL_ROUTER_CONFIG);\n return inject(DaffExternalRouterDriver).resolve(daffConvertToPath(segments)).pipe(\n map(processErrors),\n map(processRedirects),\n map((r) => ({ result: r, isMatch: type === r.type })),\n tap((r) => {\n if(r.isMatch) {\n route.title = r.result.data?.title ?? route.data?.daffSeoData?.title ?? route.title;\n route.data = { ...route.data, daffSeoData: r.result.data };\n }\n }),\n map((res) => res.isMatch),\n catchError(error => {\n if (\n !(error instanceof DaffExternalRouterPermanentRedirectError) &&\n !(error instanceof DaffExternalRouterTemporaryRedirectError)) {\n throw error;\n }\n\n return of(router.parseUrl(error.redirectUrl));\n }),\n // Handle \"404\"\n catchError((error) => {\n if (!(error instanceof DaffExternalRouterNotFoundError)) {\n throw error;\n }\n\n return of(false);\n }),\n //Otherwise something went horribly wrong and we need to bail out.\n catchError((error) => of(router.parseUrl(config.failedResolutionPath))),\n catchError(() => of(false)),\n );\n};\n\n\n","/*\n * Public API Surface of @daffodil/external-router/routing\n */\nexport { daffExternalMatcherTypeGuard } from './guard/external-matcher-type.guard';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAKA;;AAEG;AACG,MAAO,6BAA8B,SAAQ,oBAAoB,CAAA;AAIrE,IAAA,WAAA,CAAY,OAAgB,EAAA;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHD,IAAI,CAAA,IAAA,GAAW,kBAAkB,CAAC;KAIjD;AACF;;ACXD;;AAEG;AACG,MAAO,+BAAgC,SAAQ,6BAA6B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I,EAAE,WAAW,EAAE,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC;AACpF,YAAA,KAAK,CAAC,IAAI,GAAG,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;SAC5D;AACH,KAAC,CAAC,EACF,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,OAAO,CAAC,EACzB,UAAU,CAAC,KAAK,IAAG;AACjB,QAAA,IACE,EAAE,KAAK,YAAY,wCAAwC,CAAC;AAC5D,YAAA,EAAE,KAAK,YAAY,wCAAwC,CAAC,EAAE;AAC9D,YAAA,MAAM,KAAK,CAAC;SACb;QAED,OAAO,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;AAChD,KAAC,CAAC;;AAEF,IAAA,UAAU,CAAC,CAAC,KAAK,KAAI;AACnB,QAAA,IAAI,EAAE,KAAK,YAAY,+BAA+B,CAAC,EAAE;AACvD,YAAA,MAAM,KAAK,CAAC;SACb;AAED,QAAA,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;AACnB,KAAC,CAAC;;AAEF,IAAA,UAAU,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,EACvE,UAAU,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAC5B,CAAC;AACJ;;ACvEA;;AAEG;;ACFH;;AAEG;;;;"}
|
@@ -1,295 +1,23 @@
|
|
1
|
-
import {
|
2
|
-
import
|
3
|
-
import { InjectionToken, NgModule, Injectable, Inject } from '@angular/core';
|
4
|
-
import * as i1 from '@angular/router';
|
5
|
-
import { DaffInheritableError } from '@daffodil/core';
|
6
|
-
import { daffUriTruncateLeadingSlash } from '@daffodil/core/routing';
|
1
|
+
import { createConfigInjectionToken } from '@daffodil/core';
|
2
|
+
import { makeEnvironmentProviders } from '@angular/core';
|
7
3
|
|
8
4
|
const daffExternalRouterConfigurationDefault = {
|
9
5
|
failedResolutionPath: '/',
|
10
|
-
notFoundResolutionPath: '/',
|
11
6
|
};
|
7
|
+
const {
|
12
8
|
/**
|
13
9
|
* The token holding the runtime configuration for the behavior of the
|
14
10
|
* `@daffodil/external-router` package.
|
15
11
|
*/
|
16
|
-
|
17
|
-
providedIn: 'root',
|
18
|
-
factory: () => daffExternalRouterConfigurationDefault,
|
19
|
-
});
|
20
|
-
|
21
|
-
/**
|
22
|
-
* A multi-token that allows you to register route "types" that correspond to routes.
|
23
|
-
*/
|
24
|
-
const DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE = new InjectionToken('DAFF_EXTERNAL_ROUTER_RESOLVABLE_TYPE_ROUTES', {
|
25
|
-
providedIn: 'root',
|
26
|
-
factory: () => [],
|
27
|
-
});
|
28
|
-
/**
|
29
|
-
* A provider used to connect a type to a route to enable dynamic route resolution at runtime.
|
30
|
-
*/
|
31
|
-
function daffProvideRouteResolvableByType(typeRoutePair) {
|
32
|
-
return {
|
33
|
-
provide: DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE,
|
34
|
-
multi: true,
|
35
|
-
useValue: typeRoutePair,
|
36
|
-
};
|
37
|
-
}
|
38
|
-
/**
|
39
|
-
* A multi-provider used to connect an array of types to their respective routes.
|
40
|
-
*/
|
41
|
-
function daffProvideRoutesResolvableByType(routes) {
|
42
|
-
return routes.map((route) => ({
|
43
|
-
provide: DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE,
|
44
|
-
multi: true,
|
45
|
-
useValue: route,
|
46
|
-
}));
|
47
|
-
}
|
48
|
-
|
49
|
-
/**
|
50
|
-
* The external `DaffExternalRouterModule` allows you to configure the
|
51
|
-
* `@daffodil/external-router` package's behavior.
|
52
|
-
*/
|
53
|
-
class DaffExternalRouterModule {
|
54
|
-
static forRoot(config, routes = []) {
|
55
|
-
return {
|
56
|
-
ngModule: DaffExternalRouterModule,
|
57
|
-
providers: [
|
58
|
-
{ provide: DAFF_EXTERNAL_ROUTER_CONFIG, useValue: { ...daffExternalRouterConfigurationDefault, ...config } },
|
59
|
-
...daffProvideRoutesResolvableByType(routes),
|
60
|
-
],
|
61
|
-
};
|
62
|
-
}
|
63
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.2", ngImport: i0, type: DaffExternalRouterModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
64
|
-
/** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.2", ngImport: i0, type: DaffExternalRouterModule, imports: [CommonModule] }); }
|
65
|
-
/** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.2", ngImport: i0, type: DaffExternalRouterModule, imports: [CommonModule] }); }
|
66
|
-
}
|
67
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.2", ngImport: i0, type: DaffExternalRouterModule, decorators: [{
|
68
|
-
type: NgModule,
|
69
|
-
args: [{
|
70
|
-
declarations: [],
|
71
|
-
imports: [CommonModule],
|
72
|
-
}]
|
73
|
-
}] });
|
74
|
-
|
12
|
+
token: DAFF_EXTERNAL_ROUTER_CONFIG,
|
75
13
|
/**
|
76
|
-
*
|
77
|
-
* of the Angular Router.
|
14
|
+
* Provider function for {@link DAFF_EXTERNAL_ROUTER_CONFIG}.
|
78
15
|
*/
|
79
|
-
|
80
|
-
constructor(message) {
|
81
|
-
super(message);
|
82
|
-
this.code = 'NO_WILDCARD_ROUTE';
|
83
|
-
}
|
84
|
-
}
|
16
|
+
provider: provideDaffExternalRouterConfig, } = createConfigInjectionToken(daffExternalRouterConfigurationDefault, 'DAFF_EXTERNAL_ROUTER_CONFIG');
|
85
17
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
*/
|
90
|
-
const daffInsertRouteBeforeWildCardStrategy = (route, routes) => {
|
91
|
-
const index = routes.findIndex((r) => r.path === '**');
|
92
|
-
if (index === -1) {
|
93
|
-
throw new DaffExternalRouterNoWildcardError('No wildcard (**) route was found during route resolution.');
|
94
|
-
}
|
95
|
-
return [
|
96
|
-
...routes.slice(0, index),
|
97
|
-
route,
|
98
|
-
...routes.slice(index),
|
99
|
-
];
|
100
|
-
};
|
101
|
-
|
102
|
-
/**
|
103
|
-
* An error thrown when there is a failure matching a configured route to a
|
104
|
-
* route type.
|
105
|
-
*/
|
106
|
-
class DaffExternalRouterUnknownRouteTypeError extends DaffInheritableError {
|
107
|
-
constructor(message) {
|
108
|
-
super(message);
|
109
|
-
this.code = 'UNKNOWN_ROUTE_TYPE';
|
110
|
-
}
|
111
|
-
}
|
112
|
-
|
113
|
-
/**
|
114
|
-
* Transforms a DaffExternallyResolvableUrl into an Angular Route.
|
115
|
-
*/
|
116
|
-
const daffTransformResolvedRouteToRoute = (resolvedRoute, availableTypes) => {
|
117
|
-
const routeType = availableTypes
|
118
|
-
.filter(t => t.type === resolvedRoute.type)
|
119
|
-
.shift();
|
120
|
-
if (!routeType) {
|
121
|
-
throw new DaffExternalRouterUnknownRouteTypeError(`Unable to resolve the route '${resolvedRoute.url}'. Its type is '${resolvedRoute.type}' but a matching route wasn't found.`);
|
122
|
-
}
|
123
|
-
return {
|
124
|
-
route: {
|
125
|
-
path: resolvedRoute.url,
|
126
|
-
daffExternalRouteType: resolvedRoute.type,
|
127
|
-
...routeType.route,
|
128
|
-
data: {
|
129
|
-
...resolvedRoute.data,
|
130
|
-
},
|
131
|
-
},
|
132
|
-
insertionStrategy: routeType.insertionStrategy,
|
133
|
-
};
|
134
|
-
};
|
135
|
-
|
136
|
-
class DaffExternalRouter {
|
137
|
-
constructor(router, runtimeRoutes) {
|
138
|
-
this.router = router;
|
139
|
-
this.runtimeRoutes = runtimeRoutes;
|
140
|
-
}
|
141
|
-
/**
|
142
|
-
* Adds a route to the existing router configuration.
|
143
|
-
*/
|
144
|
-
add(resolvedRoute) {
|
145
|
-
//Get the route.
|
146
|
-
const { route, insertionStrategy, } = daffTransformResolvedRouteToRoute(resolvedRoute, this.runtimeRoutes);
|
147
|
-
try {
|
148
|
-
//Add it to configuration.
|
149
|
-
this.router.config = (insertionStrategy || daffInsertRouteBeforeWildCardStrategy)(route, this.router.config);
|
150
|
-
}
|
151
|
-
catch (e) {
|
152
|
-
if (e instanceof DaffExternalRouterNoWildcardError) {
|
153
|
-
throw new DaffExternalRouterNoWildcardError(`${e.message} This usually means you have misconfigured your routes.`);
|
154
|
-
}
|
155
|
-
throw e;
|
156
|
-
}
|
157
|
-
}
|
158
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.2", ngImport: i0, type: DaffExternalRouter, deps: [{ token: i1.Router }, { token: DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
159
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.2", ngImport: i0, type: DaffExternalRouter, providedIn: 'root' }); }
|
160
|
-
}
|
161
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.2", ngImport: i0, type: DaffExternalRouter, decorators: [{
|
162
|
-
type: Injectable,
|
163
|
-
args: [{
|
164
|
-
providedIn: 'root',
|
165
|
-
}]
|
166
|
-
}], ctorParameters: () => [{ type: i1.Router }, { type: undefined, decorators: [{
|
167
|
-
type: Inject,
|
168
|
-
args: [DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE]
|
169
|
-
}] }] });
|
170
|
-
|
171
|
-
/**
|
172
|
-
* Tests whether or not a route matches a specific Daffodil Route type.
|
173
|
-
*
|
174
|
-
* See {@link DaffRouteWithDataPath}
|
175
|
-
*/
|
176
|
-
const routeMatchesRouteType = (route, type) => route?.data?.daffExternalRouteType === type;
|
177
|
-
/**
|
178
|
-
* Adds a path to the `daffPaths` of the given route.
|
179
|
-
*
|
180
|
-
* See {@link DaffRouteWithDataPath}
|
181
|
-
*/
|
182
|
-
const addRouteToDaffPaths = (route, externalRoute) => {
|
183
|
-
route.data.daffPaths = {
|
184
|
-
...route.data.daffPaths,
|
185
|
-
[externalRoute.path]: externalRoute.data,
|
186
|
-
};
|
187
|
-
return route;
|
188
|
-
};
|
189
|
-
const operateOnRoute = (externalRoute) => (route) => addRouteToDaffPaths(route, externalRoute);
|
190
|
-
/**
|
191
|
-
* Traverse the router config tree, halting after the first match.
|
192
|
-
* This traversal is implemented in a pre-order manner. As such, for large
|
193
|
-
* configuration trees, it will be most efficient to place externally routed
|
194
|
-
* components at the top of router configuration.
|
195
|
-
*/
|
196
|
-
const traverseRouteTree = (routes = [], matcher, operate) => {
|
197
|
-
if (routes.length === 0) {
|
198
|
-
return routes;
|
199
|
-
}
|
200
|
-
const stack = [];
|
201
|
-
const treeRoot = { children: routes };
|
202
|
-
stack.push(treeRoot);
|
203
|
-
while (stack.length) {
|
204
|
-
const route = stack.pop();
|
205
|
-
if (matcher(route)) {
|
206
|
-
operate(route);
|
207
|
-
break;
|
208
|
-
}
|
209
|
-
if (route.children) {
|
210
|
-
stack.push(...route.children.reverse());
|
211
|
-
}
|
212
|
-
}
|
213
|
-
return routes;
|
214
|
-
};
|
215
|
-
/**
|
216
|
-
* A route insertion strategy that can be used to append external routes onto
|
217
|
-
* existing Angular routes. This can be useful when you need to route to
|
218
|
-
* an existing lazy-loaded module from multiple externally defined urls.
|
219
|
-
*
|
220
|
-
* This should be used in combination with the {@link daffDataPathUrlMatcher} to match lazy-loaded modules with
|
221
|
-
* associated external urls.
|
222
|
-
*
|
223
|
-
* For example, you can provide the insertion strategy in the {@link DaffExternalRouterModule} as below.
|
224
|
-
*
|
225
|
-
* ```ts
|
226
|
-
* DaffExternalRouterModule.forRoot({}, [
|
227
|
-
* {
|
228
|
-
* type: 'CATEGORY',
|
229
|
-
* insertionStrategy: daffInsertDataPathStrategy,
|
230
|
-
* route: {}
|
231
|
-
* }
|
232
|
-
* ],
|
233
|
-
* ```
|
234
|
-
*
|
235
|
-
* Then, you can match it with an associated route defined in your Routing
|
236
|
-
* configuration with the {@link daffDataPathUrlMatcher}.
|
237
|
-
*
|
238
|
-
* ```ts
|
239
|
-
* export const routes: Routes = [
|
240
|
-
* {
|
241
|
-
* matcher: daffDataPathUrlMatcher,
|
242
|
-
* data: {
|
243
|
-
* daffExternalRouteType: "CATEGORY",
|
244
|
-
* },
|
245
|
-
* loadChildren: () => import('./category/category.module').then((m) => m.MyCategoryModule),
|
246
|
-
* }
|
247
|
-
* ]
|
248
|
-
* ```
|
249
|
-
*
|
250
|
-
* See {@link DaffRouteWithDataPath}
|
251
|
-
*
|
252
|
-
*/
|
253
|
-
const daffInsertDataPathStrategy = (externalRoute, routes) => traverseRouteTree(routes, (route) => routeMatchesRouteType(route, externalRoute.daffExternalRouteType), operateOnRoute(externalRoute));
|
254
|
-
|
255
|
-
/**
|
256
|
-
* A UrlMatcher that does an exact match against a path stored in the special
|
257
|
-
* configuration fields that External Router stores on a Route's data.
|
258
|
-
*
|
259
|
-
* ```ts
|
260
|
-
* export const routes: Routes = [
|
261
|
-
* {
|
262
|
-
* matcher: daffDataPathUrlMatcher,
|
263
|
-
* data: {
|
264
|
-
* daffExternalRouteType: "CATEGORY",
|
265
|
-
* },
|
266
|
-
* loadChildren: () => import('./category/category.module').then((m) => m.ShopCategoryModule),
|
267
|
-
* }
|
268
|
-
* ]
|
269
|
-
* ```
|
270
|
-
* {@link daffInsertDataPathStrategy }
|
271
|
-
* {@link DaffRouteWithDataPath }
|
272
|
-
*/
|
273
|
-
const daffDataPathUrlMatcher = (segments, group, route) => {
|
274
|
-
const path = daffUriTruncateLeadingSlash(segments.reduce((acc, segment) => acc + '/' + segment.path, ''));
|
275
|
-
const paths = route?.data?.daffPaths;
|
276
|
-
// If we don't have any paths, we can safely fail a match.
|
277
|
-
if (!paths) {
|
278
|
-
return null;
|
279
|
-
}
|
280
|
-
// Otherwise, look up the path in the dictionary, failing if a match isn't found,
|
281
|
-
// but matching the entire segment if a match is found.
|
282
|
-
return path in paths ? { consumed: segments } : null;
|
283
|
-
};
|
284
|
-
|
285
|
-
/**
|
286
|
-
* Extracts a key from DaffPath data based upon the currently activated
|
287
|
-
* RouteSnapshot.
|
288
|
-
*/
|
289
|
-
const daffExtractDaffPathData = (snapshot, key) => {
|
290
|
-
const pathFromRoot = snapshot.pathFromRoot.flatMap((route) => route.url).map((seg) => seg.path).join('/');
|
291
|
-
return snapshot.data?.daffPaths?.[pathFromRoot]?.[key] ?? null;
|
292
|
-
};
|
18
|
+
const provideExternalRouter = (config = {}) => makeEnvironmentProviders([
|
19
|
+
provideDaffExternalRouterConfig(config),
|
20
|
+
]);
|
293
21
|
|
294
22
|
/*
|
295
23
|
* Public API Surface of @daffodil/external-router
|
@@ -299,5 +27,5 @@ const daffExtractDaffPathData = (snapshot, key) => {
|
|
299
27
|
* Generated bundle index. Do not edit.
|
300
28
|
*/
|
301
29
|
|
302
|
-
export { DAFF_EXTERNAL_ROUTER_CONFIG,
|
30
|
+
export { DAFF_EXTERNAL_ROUTER_CONFIG, provideExternalRouter };
|
303
31
|
//# sourceMappingURL=daffodil-external-router.mjs.map
|