@daffodil/external-router 0.39.12 → 0.41.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/daffodil-external-router.d.ts +1 -1
- package/driver/daffodil-external-router-driver.d.ts +1 -0
- package/driver/in-memory/daffodil-external-router-driver-in-memory.d.ts +1 -1
- package/driver/in-memory/in-memory.module.d.ts +5 -0
- package/driver/in-memory/in-memory.service.d.ts +3 -0
- package/driver/in-memory/package.json +5 -6
- package/driver/magento/2.4.1/daffodil-external-router-driver-magento-2.4.1.d.ts +1 -1
- package/driver/magento/2.4.1/graphql/queries/resolve-url-v2.4.1.d.ts +1 -1
- package/driver/magento/2.4.1/magento.module.d.ts +5 -0
- package/driver/magento/2.4.1/magento.service.d.ts +3 -0
- package/driver/magento/2.4.1/package.json +5 -6
- package/driver/magento/2.4.2/daffodil-external-router-driver-magento-2.4.2.d.ts +1 -1
- package/driver/magento/2.4.2/graphql/queries/resolve-url-v2.4.2.d.ts +1 -1
- package/driver/magento/2.4.2/magento.module.d.ts +5 -0
- package/driver/magento/2.4.2/magento.service.d.ts +3 -0
- package/driver/magento/2.4.2/package.json +5 -6
- package/driver/magento/daffodil-external-router-driver-magento.d.ts +1 -0
- package/driver/magento/package.json +5 -6
- package/driver/package.json +5 -6
- package/driver/testing/daffodil-external-router-driver-testing.d.ts +1 -1
- package/driver/testing/package.json +5 -6
- package/driver/testing/testing.module.d.ts +5 -0
- package/driver/testing/testing.service.d.ts +3 -0
- package/{esm2015/config.js → esm2020/config.mjs} +0 -0
- package/esm2020/daffodil-external-router.mjs +5 -0
- package/{esm2015/driver/daffodil-external-router-driver.js → esm2020/driver/daffodil-external-router-driver.mjs} +0 -0
- package/esm2020/driver/in-memory/config.mjs +15 -0
- package/{esm2015/driver/in-memory/daffodil-external-router-driver-in-memory.js → esm2020/driver/in-memory/daffodil-external-router-driver-in-memory.mjs} +1 -2
- package/esm2020/driver/in-memory/in-memory.module.mjs +41 -0
- package/esm2020/driver/in-memory/in-memory.service.mjs +39 -0
- package/{esm2015/driver/in-memory/index.js → esm2020/driver/in-memory/index.mjs} +0 -0
- package/{esm2015/driver/in-memory/public_api.js → esm2020/driver/in-memory/public_api.mjs} +0 -0
- package/{esm2015/driver/index.js → esm2020/driver/index.mjs} +0 -0
- package/{esm2015/driver/interfaces/external-router-driver.interface.js → esm2020/driver/interfaces/external-router-driver.interface.mjs} +0 -0
- package/esm2020/driver/magento/2.4.1/daffodil-external-router-driver-magento-2.4.1.mjs +5 -0
- package/{esm2015/driver/magento/2.4.1/graphql/queries/resolve-url-v2.4.1.js → esm2020/driver/magento/2.4.1/graphql/queries/resolve-url-v2.4.1.mjs} +0 -0
- package/{esm2015/driver/magento/2.4.1/index.js → esm2020/driver/magento/2.4.1/index.mjs} +0 -0
- package/esm2020/driver/magento/2.4.1/magento.module.mjs +55 -0
- package/esm2020/driver/magento/2.4.1/magento.service.mjs +38 -0
- package/{esm2015/driver/magento/2.4.1/public_api.js → esm2020/driver/magento/2.4.1/public_api.mjs} +0 -0
- package/esm2020/driver/magento/2.4.1/transforms/resolution-to-resolvable-url.mjs +10 -0
- package/esm2020/driver/magento/2.4.2/daffodil-external-router-driver-magento-2.4.2.mjs +5 -0
- package/{esm2015/driver/magento/2.4.2/graphql/queries/resolve-url-v2.4.2.js → esm2020/driver/magento/2.4.2/graphql/queries/resolve-url-v2.4.2.mjs} +0 -0
- package/{esm2015/driver/magento/2.4.2/index.js → esm2020/driver/magento/2.4.2/index.mjs} +0 -0
- package/esm2020/driver/magento/2.4.2/magento.module.mjs +55 -0
- package/esm2020/driver/magento/2.4.2/magento.service.mjs +37 -0
- package/{esm2015/driver/magento/2.4.2/public_api.js → esm2020/driver/magento/2.4.2/public_api.mjs} +0 -0
- package/{esm2015/driver/magento/2.4.2/transforms/resolution-to-resolvable-url.js → esm2020/driver/magento/2.4.2/transforms/resolution-to-resolvable-url.mjs} +0 -0
- package/{esm2015/driver/magento/daffodil-external-router-driver-magento.js → esm2020/driver/magento/daffodil-external-router-driver-magento.mjs} +0 -0
- package/{esm2015/driver/magento/index.js → esm2020/driver/magento/index.mjs} +0 -0
- package/{esm2015/driver/magento/model/public_api.js → esm2020/driver/magento/model/public_api.mjs} +0 -0
- package/{esm2015/driver/magento/model/resolution-types.js → esm2020/driver/magento/model/resolution-types.mjs} +0 -0
- package/{esm2015/driver/magento/model/url-resolver-response.js → esm2020/driver/magento/model/url-resolver-response.mjs} +0 -0
- package/{esm2015/driver/magento/model/url-resolver.js → esm2020/driver/magento/model/url-resolver.mjs} +0 -0
- package/{esm2015/driver/magento/public_api.js → esm2020/driver/magento/public_api.mjs} +0 -0
- package/{esm2015/driver/magento/transforms/public_api.js → esm2020/driver/magento/transforms/public_api.mjs} +0 -0
- package/{esm2015/driver/magento/transforms/redirect-to-http.js → esm2020/driver/magento/transforms/redirect-to-http.mjs} +0 -0
- package/{esm2015/driver/not-found-resolution.js → esm2020/driver/not-found-resolution.mjs} +0 -0
- package/{esm2015/driver/public_api.js → esm2020/driver/public_api.mjs} +0 -0
- package/{esm2015/driver/testing/config.js → esm2020/driver/testing/config.mjs} +0 -0
- package/esm2020/driver/testing/daffodil-external-router-driver-testing.mjs +5 -0
- package/{esm2015/driver/testing/index.js → esm2020/driver/testing/index.mjs} +0 -0
- package/{esm2015/driver/testing/public_api.js → esm2020/driver/testing/public_api.mjs} +0 -0
- package/esm2020/driver/testing/testing.module.mjs +38 -0
- package/esm2020/driver/testing/testing.service.mjs +45 -0
- package/{esm2015/errors/no-wildcard.js → esm2020/errors/no-wildcard.mjs} +0 -0
- package/{esm2015/errors/unknown-type.js → esm2020/errors/unknown-type.mjs} +0 -0
- package/esm2020/external-router.module.mjs +31 -0
- package/{esm2015/model/insertion-strategy.type.js → esm2020/model/insertion-strategy.type.mjs} +0 -0
- package/{esm2015/model/public_api.js → esm2020/model/public_api.mjs} +0 -0
- package/{esm2015/model/resolvable-route.js → esm2020/model/resolvable-route.mjs} +0 -0
- package/{esm2015/model/route-info.js → esm2020/model/route-info.mjs} +0 -0
- package/{esm2015/model/route-type.js → esm2020/model/route-type.mjs} +0 -0
- package/{esm2015/model/route-with-data-path.js → esm2020/model/route-with-data-path.mjs} +0 -0
- package/{esm2015/model/route-without-path.js → esm2020/model/route-without-path.mjs} +0 -0
- package/{esm2015/model/type-route-pair.js → esm2020/model/type-route-pair.mjs} +0 -0
- package/{esm2015/public_api.js → esm2020/public_api.mjs} +0 -0
- package/esm2020/router/router.service.mjs +43 -0
- package/esm2020/router/strategies/insert-data-path.mjs +81 -0
- package/{esm2015/router/strategies/insert-route-before-wildcard.js → esm2020/router/strategies/insert-route-before-wildcard.mjs} +0 -0
- package/esm2020/router/url-matcher/data-path-matcher.mjs +31 -0
- package/{esm2015/routing/daffodil-external-router-routing.js → esm2020/routing/daffodil-external-router-routing.mjs} +0 -0
- package/{esm2015/routing/errors/client-error.js → esm2020/routing/errors/client-error.mjs} +0 -0
- package/{esm2015/routing/errors/not-found-error.js → esm2020/routing/errors/not-found-error.mjs} +0 -0
- package/{esm2015/routing/errors/permanent-redirect.js → esm2020/routing/errors/permanent-redirect.mjs} +0 -0
- package/{esm2015/routing/errors/server-error.js → esm2020/routing/errors/server-error.mjs} +0 -0
- package/{esm2015/routing/errors/temporary-redirect.js → esm2020/routing/errors/temporary-redirect.mjs} +0 -0
- package/esm2020/routing/guard/existence.guard.mjs +77 -0
- package/{esm2015/routing/index.js → esm2020/routing/index.mjs} +0 -0
- package/{esm2015/routing/processors/process-errors.js → esm2020/routing/processors/process-errors.mjs} +0 -0
- package/{esm2015/routing/processors/process-redirect.js → esm2020/routing/processors/process-redirect.mjs} +0 -0
- package/{esm2015/routing/public_api.js → esm2020/routing/public_api.mjs} +0 -0
- package/{esm2015/token/type-resolvable-routes.token.js → esm2020/token/type-resolvable-routes.token.mjs} +0 -0
- package/esm2020/transform/resolved-route-to-route.mjs +24 -0
- package/external-router.module.d.ts +5 -0
- package/fesm2015/{daffodil-external-router-driver-in-memory.js → daffodil-external-router-driver-in-memory.mjs} +28 -21
- package/fesm2015/daffodil-external-router-driver-in-memory.mjs.map +1 -0
- package/fesm2015/{daffodil-external-router-driver-magento-2.4.1.js → daffodil-external-router-driver-magento-2.4.1.mjs} +24 -20
- package/fesm2015/daffodil-external-router-driver-magento-2.4.1.mjs.map +1 -0
- package/fesm2015/{daffodil-external-router-driver-magento-2.4.2.js → daffodil-external-router-driver-magento-2.4.2.mjs} +24 -20
- package/fesm2015/daffodil-external-router-driver-magento-2.4.2.mjs.map +1 -0
- package/fesm2015/{daffodil-external-router-driver-magento.js → daffodil-external-router-driver-magento.mjs} +1 -1
- package/fesm2015/daffodil-external-router-driver-magento.mjs.map +1 -0
- package/fesm2015/daffodil-external-router-driver-testing.mjs +101 -0
- package/fesm2015/daffodil-external-router-driver-testing.mjs.map +1 -0
- package/fesm2015/{daffodil-external-router-driver.js → daffodil-external-router-driver.mjs} +1 -1
- package/fesm2015/daffodil-external-router-driver.mjs.map +1 -0
- package/fesm2015/daffodil-external-router-routing.mjs +173 -0
- package/fesm2015/daffodil-external-router-routing.mjs.map +1 -0
- package/fesm2015/{daffodil-external-router.js → daffodil-external-router.mjs} +28 -25
- package/fesm2015/daffodil-external-router.mjs.map +1 -0
- package/fesm2020/daffodil-external-router-driver-in-memory.mjs +98 -0
- package/fesm2020/daffodil-external-router-driver-in-memory.mjs.map +1 -0
- package/fesm2020/daffodil-external-router-driver-magento-2.4.1.mjs +122 -0
- package/fesm2020/daffodil-external-router-driver-magento-2.4.1.mjs.map +1 -0
- package/fesm2020/daffodil-external-router-driver-magento-2.4.2.mjs +122 -0
- package/fesm2020/daffodil-external-router-driver-magento-2.4.2.mjs.map +1 -0
- package/fesm2020/daffodil-external-router-driver-magento.mjs +22 -0
- package/fesm2020/daffodil-external-router-driver-magento.mjs.map +1 -0
- package/fesm2020/daffodil-external-router-driver-testing.mjs +99 -0
- package/fesm2020/daffodil-external-router-driver-testing.mjs.map +1 -0
- package/fesm2020/daffodil-external-router-driver.mjs +30 -0
- package/fesm2020/daffodil-external-router-driver.mjs.map +1 -0
- package/{fesm2015/daffodil-external-router-routing.js → fesm2020/daffodil-external-router-routing.mjs} +21 -19
- package/fesm2020/daffodil-external-router-routing.mjs.map +1 -0
- package/fesm2020/daffodil-external-router.mjs +291 -0
- package/fesm2020/daffodil-external-router.mjs.map +1 -0
- package/package.json +83 -15
- package/router/router.service.d.ts +3 -0
- package/routing/daffodil-external-router-routing.d.ts +1 -0
- package/routing/guard/existence.guard.d.ts +3 -0
- package/routing/package.json +5 -6
- package/bundles/daffodil-external-router-driver-in-memory.umd.js +0 -100
- package/bundles/daffodil-external-router-driver-in-memory.umd.js.map +0 -1
- package/bundles/daffodil-external-router-driver-in-memory.umd.min.js +0 -2
- package/bundles/daffodil-external-router-driver-in-memory.umd.min.js.map +0 -1
- package/bundles/daffodil-external-router-driver-magento-2.4.1.umd.js +0 -438
- package/bundles/daffodil-external-router-driver-magento-2.4.1.umd.js.map +0 -1
- package/bundles/daffodil-external-router-driver-magento-2.4.1.umd.min.js +0 -16
- package/bundles/daffodil-external-router-driver-magento-2.4.1.umd.min.js.map +0 -1
- package/bundles/daffodil-external-router-driver-magento-2.4.2.umd.js +0 -435
- package/bundles/daffodil-external-router-driver-magento-2.4.2.umd.js.map +0 -1
- package/bundles/daffodil-external-router-driver-magento-2.4.2.umd.min.js +0 -16
- package/bundles/daffodil-external-router-driver-magento-2.4.2.umd.min.js.map +0 -1
- package/bundles/daffodil-external-router-driver-magento.umd.js +0 -31
- package/bundles/daffodil-external-router-driver-magento.umd.js.map +0 -1
- package/bundles/daffodil-external-router-driver-magento.umd.min.js +0 -2
- package/bundles/daffodil-external-router-driver-magento.umd.min.js.map +0 -1
- package/bundles/daffodil-external-router-driver-testing.umd.js +0 -101
- package/bundles/daffodil-external-router-driver-testing.umd.js.map +0 -1
- package/bundles/daffodil-external-router-driver-testing.umd.min.js +0 -2
- package/bundles/daffodil-external-router-driver-testing.umd.min.js.map +0 -1
- package/bundles/daffodil-external-router-driver.umd.js +0 -39
- package/bundles/daffodil-external-router-driver.umd.js.map +0 -1
- package/bundles/daffodil-external-router-driver.umd.min.js +0 -2
- package/bundles/daffodil-external-router-driver.umd.min.js.map +0 -1
- package/bundles/daffodil-external-router-routing.umd.js +0 -505
- package/bundles/daffodil-external-router-routing.umd.js.map +0 -1
- package/bundles/daffodil-external-router-routing.umd.min.js +0 -16
- package/bundles/daffodil-external-router-routing.umd.min.js.map +0 -1
- package/bundles/daffodil-external-router.umd.js +0 -625
- package/bundles/daffodil-external-router.umd.js.map +0 -1
- package/bundles/daffodil-external-router.umd.min.js +0 -16
- package/bundles/daffodil-external-router.umd.min.js.map +0 -1
- package/daffodil-external-router.metadata.json +0 -1
- package/driver/daffodil-external-router-driver.metadata.json +0 -1
- package/driver/in-memory/daffodil-external-router-driver-in-memory.metadata.json +0 -1
- package/driver/magento/2.4.1/daffodil-external-router-driver-magento-2.4.1.metadata.json +0 -1
- package/driver/magento/2.4.2/daffodil-external-router-driver-magento-2.4.2.metadata.json +0 -1
- package/driver/magento/daffodil-external-router-driver-magento.metadata.json +0 -1
- package/driver/testing/daffodil-external-router-driver-testing.metadata.json +0 -1
- package/esm2015/daffodil-external-router.js +0 -6
- package/esm2015/driver/in-memory/config.js +0 -17
- package/esm2015/driver/in-memory/in-memory.module.js +0 -36
- package/esm2015/driver/in-memory/in-memory.service.js +0 -36
- package/esm2015/driver/magento/2.4.1/daffodil-external-router-driver-magento-2.4.1.js +0 -6
- package/esm2015/driver/magento/2.4.1/magento.module.js +0 -50
- package/esm2015/driver/magento/2.4.1/magento.service.js +0 -40
- package/esm2015/driver/magento/2.4.1/transforms/resolution-to-resolvable-url.js +0 -13
- package/esm2015/driver/magento/2.4.2/daffodil-external-router-driver-magento-2.4.2.js +0 -6
- package/esm2015/driver/magento/2.4.2/magento.module.js +0 -50
- package/esm2015/driver/magento/2.4.2/magento.service.js +0 -39
- package/esm2015/driver/testing/daffodil-external-router-driver-testing.js +0 -6
- package/esm2015/driver/testing/testing.module.js +0 -33
- package/esm2015/driver/testing/testing.service.js +0 -45
- package/esm2015/external-router.module.js +0 -26
- package/esm2015/router/router.service.js +0 -44
- package/esm2015/router/strategies/insert-data-path.js +0 -83
- package/esm2015/router/url-matcher/data-path-matcher.js +0 -32
- package/esm2015/routing/guard/existence.guard.js +0 -78
- package/esm2015/transform/resolved-route-to-route.js +0 -17
- package/fesm2015/daffodil-external-router-driver-in-memory.js.map +0 -1
- package/fesm2015/daffodil-external-router-driver-magento-2.4.1.js.map +0 -1
- package/fesm2015/daffodil-external-router-driver-magento-2.4.2.js.map +0 -1
- package/fesm2015/daffodil-external-router-driver-magento.js.map +0 -1
- package/fesm2015/daffodil-external-router-driver-testing.js +0 -93
- package/fesm2015/daffodil-external-router-driver-testing.js.map +0 -1
- package/fesm2015/daffodil-external-router-driver.js.map +0 -1
- package/fesm2015/daffodil-external-router-routing.js.map +0 -1
- package/fesm2015/daffodil-external-router.js.map +0 -1
- package/routing/daffodil-external-router-routing.metadata.json +0 -1
@@ -0,0 +1,173 @@
|
|
1
|
+
import * as i0 from '@angular/core';
|
2
|
+
import { Injectable, Inject } from '@angular/core';
|
3
|
+
import { of } from 'rxjs';
|
4
|
+
import { map, switchMap, catchError } from 'rxjs/operators';
|
5
|
+
import * as i1 from '@daffodil/external-router';
|
6
|
+
import { DAFF_EXTERNAL_ROUTER_CONFIG } from '@daffodil/external-router';
|
7
|
+
import { DaffExternalRouterDriver } from '@daffodil/external-router/driver';
|
8
|
+
import { DaffInheritableError } from '@daffodil/core';
|
9
|
+
import * as i2 from '@angular/router';
|
10
|
+
import * as i3 from '@daffodil/core/routing';
|
11
|
+
|
12
|
+
/**
|
13
|
+
* An error thrown when the driver encounters a 4xx error.
|
14
|
+
*/
|
15
|
+
class DaffExternalRouterClientError extends DaffInheritableError {
|
16
|
+
constructor(message) {
|
17
|
+
super(message);
|
18
|
+
this.code = '4xx_CLIENT_ERROR';
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
/**
|
23
|
+
* An error thrown when the driver determines that a given url is not resolvable.
|
24
|
+
*/
|
25
|
+
class DaffExternalRouterNotFoundError extends DaffExternalRouterClientError {
|
26
|
+
constructor(message) {
|
27
|
+
super(message);
|
28
|
+
this.code = '404_NOT_FOUND';
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* An error thrown when the driver determines that the url needs to be routed somewhere
|
34
|
+
* else permanently.
|
35
|
+
*/
|
36
|
+
class DaffExternalRouterPermanentRedirectError extends DaffInheritableError {
|
37
|
+
constructor(redirectUrl, message) {
|
38
|
+
super(message);
|
39
|
+
this.redirectUrl = redirectUrl;
|
40
|
+
this.code = '302_PERMANENT_REDIRECT';
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* An error thrown when the driver needs a URI to be temporarily redirected
|
46
|
+
* to another location.
|
47
|
+
*/
|
48
|
+
class DaffExternalRouterTemporaryRedirectError extends DaffInheritableError {
|
49
|
+
constructor(redirectUrl, message) {
|
50
|
+
super(message);
|
51
|
+
this.redirectUrl = redirectUrl;
|
52
|
+
this.code = 'TEMPORARY_REDIRECT';
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* An error thrown when the platform performing url resolution fails.
|
58
|
+
*/
|
59
|
+
class DaffExternalRouterServerError extends DaffInheritableError {
|
60
|
+
constructor(message) {
|
61
|
+
super(message);
|
62
|
+
this.code = '5xx_SERVER_ERROR';
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Processes resolved URLs and throws the appropriate error so that External Router
|
68
|
+
* can handle routing errors.
|
69
|
+
*/
|
70
|
+
const processErrors = (url) => {
|
71
|
+
if (url.code === 404) {
|
72
|
+
throw new DaffExternalRouterNotFoundError();
|
73
|
+
}
|
74
|
+
else if (url.code >= 400 && url.code < 500) {
|
75
|
+
throw new DaffExternalRouterClientError();
|
76
|
+
}
|
77
|
+
else if (url.code >= 500) {
|
78
|
+
throw new DaffExternalRouterServerError();
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
return url;
|
82
|
+
}
|
83
|
+
};
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Processes resolvedUrls and throws the appropriate error so that External Router
|
87
|
+
* can handle redirects.
|
88
|
+
*/
|
89
|
+
const processRedirects = (url) => {
|
90
|
+
if (url.code === 301) {
|
91
|
+
throw new DaffExternalRouterPermanentRedirectError(url.url);
|
92
|
+
}
|
93
|
+
else if (url.code === 302) {
|
94
|
+
throw new DaffExternalRouterTemporaryRedirectError(url.url);
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
return url;
|
98
|
+
}
|
99
|
+
};
|
100
|
+
|
101
|
+
/**
|
102
|
+
* The DaffExternalRouterExistenceGuard is responsible for guarding the wildcard route
|
103
|
+
* of an Angular App and either navigating to a resolved route upon successful resolution
|
104
|
+
* or navigating to the configured route upon a failed resolution.
|
105
|
+
*/
|
106
|
+
class DaffExternalRouterExistenceGuard {
|
107
|
+
constructor(driver, externalRouter, router, config, urlNormalizer) {
|
108
|
+
this.driver = driver;
|
109
|
+
this.externalRouter = externalRouter;
|
110
|
+
this.router = router;
|
111
|
+
this.config = config;
|
112
|
+
this.urlNormalizer = urlNormalizer;
|
113
|
+
}
|
114
|
+
canActivate(next, state) {
|
115
|
+
return this.driver.resolve(this.urlNormalizer.normalize(state.url)).pipe(map((resolvedRoute) => processErrors(resolvedRoute)), switchMap(resolvedRoute => {
|
116
|
+
this.externalRouter.add(resolvedRoute);
|
117
|
+
return of(resolvedRoute);
|
118
|
+
}), map((resolvedRoute) => processRedirects(resolvedRoute)),
|
119
|
+
// Note that we have to use state.url as we want to ensure that we keep any fragments or query strings.
|
120
|
+
// When we succeed, redirect to the new route, as config has changed since we init'd.
|
121
|
+
map(() => this.router.parseUrl(state.url)),
|
122
|
+
// When we fail, we need to process errors as dictated by the error type.
|
123
|
+
// Handle redirects
|
124
|
+
catchError(error => {
|
125
|
+
if (!(error instanceof DaffExternalRouterPermanentRedirectError) &&
|
126
|
+
!(error instanceof DaffExternalRouterTemporaryRedirectError)) {
|
127
|
+
throw error;
|
128
|
+
}
|
129
|
+
return of(this.router.parseUrl(error.redirectUrl));
|
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
|
+
}
|
147
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterExistenceGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", 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 });
|
148
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterExistenceGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterExistenceGuard, providedIn: 'root' });
|
149
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterExistenceGuard, decorators: [{
|
150
|
+
type: Injectable,
|
151
|
+
args: [{
|
152
|
+
providedIn: 'root',
|
153
|
+
}]
|
154
|
+
}], ctorParameters: function () {
|
155
|
+
return [{ type: undefined, decorators: [{
|
156
|
+
type: Inject,
|
157
|
+
args: [DaffExternalRouterDriver]
|
158
|
+
}] }, { type: i1.DaffExternalRouter }, { type: i2.Router }, { type: undefined, decorators: [{
|
159
|
+
type: Inject,
|
160
|
+
args: [DAFF_EXTERNAL_ROUTER_CONFIG]
|
161
|
+
}] }, { type: i3.DaffRoutingUriNormalizer }];
|
162
|
+
} });
|
163
|
+
|
164
|
+
/*
|
165
|
+
* Public API Surface of @daffodil/external-router/routing
|
166
|
+
*/
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Generated bundle index. Do not edit.
|
170
|
+
*/
|
171
|
+
|
172
|
+
export { DaffExternalRouterExistenceGuard };
|
173
|
+
//# sourceMappingURL=daffodil-external-router-routing.mjs.map
|
@@ -0,0 +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\tpublic readonly code: string = '4xx_CLIENT_ERROR';\n\n\tconstructor(message?: string) {\n\t super(message);\n\t}\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\tpublic readonly code: string = '404_NOT_FOUND';\n\n\tconstructor(message?: string) {\n\t super(message);\n\t}\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\tpublic readonly code: string = '302_PERMANENT_REDIRECT';\n\n\tconstructor(public redirectUrl: string, message?: string) {\n\t super(message);\n\t}\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\tpublic readonly code: string = 'TEMPORARY_REDIRECT';\n\n\tconstructor(public redirectUrl: string, message?: string) {\n\t super(message);\n\t}\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\tpublic readonly code: string = '5xx_SERVER_ERROR';\n\n\tconstructor(message?: string) {\n\t super(message);\n\t}\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 CanActivate,\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 implements CanActivate {\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;AAItE,IAAA,WAAA,CAAY,OAAgB,EAAA;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;AAHD,QAAA,IAAI,CAAA,IAAA,GAAW,kBAAkB,CAAC;KAIjD;AACD;;ACXD;;AAEG;AACG,MAAO,+BAAgC,SAAQ,6BAA6B,CAAA;AAIjF,IAAA,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EAAA,EAAA,CAAA,wBAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAN1B,sCAAA,gCAAA,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;2FAEP,gCAAgC,EAAA,UAAA,EAAA,CAAA;kBAH5C,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;iBACnB,CAAA;;;8BAGI,MAAM;+BAAC,wBAAwB,CAAA;;8BAI/B,MAAM;+BAAC,2BAA2B,CAAA;;;;ACvDvC;;AAEG;;ACFH;;AAEG;;;;"}
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { CommonModule } from '@angular/common';
|
2
|
-
import
|
3
|
-
import {
|
2
|
+
import * as i0 from '@angular/core';
|
3
|
+
import { InjectionToken, NgModule, Injectable, Inject } from '@angular/core';
|
4
4
|
import { DaffInheritableError } from '@daffodil/core';
|
5
|
+
import * as i1 from '@angular/router';
|
5
6
|
import { daffUriTruncateLeadingSlash } from '@daffodil/core/routing';
|
6
7
|
|
7
8
|
const daffExternalRouterConfigurationDefault = {
|
@@ -60,12 +61,16 @@ class DaffExternalRouterModule {
|
|
60
61
|
};
|
61
62
|
}
|
62
63
|
}
|
63
|
-
DaffExternalRouterModule
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
65
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterModule, imports: [CommonModule] });
|
66
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterModule, imports: [[CommonModule]] });
|
67
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterModule, decorators: [{
|
68
|
+
type: NgModule,
|
69
|
+
args: [{
|
70
|
+
declarations: [],
|
71
|
+
imports: [CommonModule],
|
72
|
+
}]
|
73
|
+
}] });
|
69
74
|
|
70
75
|
/**
|
71
76
|
* An error thrown when there was no wildcard route found in configuration
|
@@ -144,17 +149,19 @@ class DaffExternalRouter {
|
|
144
149
|
}
|
145
150
|
}
|
146
151
|
}
|
147
|
-
/** @nocollapse */ DaffExternalRouter.ɵ
|
148
|
-
DaffExternalRouter
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
]
|
152
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouter, deps: [{ token: i1.Router }, { token: DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE }], target: i0.ɵɵFactoryTarget.Injectable });
|
153
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouter, providedIn: 'root' });
|
154
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouter, decorators: [{
|
155
|
+
type: Injectable,
|
156
|
+
args: [{
|
157
|
+
providedIn: 'root',
|
158
|
+
}]
|
159
|
+
}], ctorParameters: function () {
|
160
|
+
return [{ type: i1.Router }, { type: undefined, decorators: [{
|
161
|
+
type: Inject,
|
162
|
+
args: [DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE]
|
163
|
+
}] }];
|
164
|
+
} });
|
158
165
|
|
159
166
|
/**
|
160
167
|
* Tests whether or not a route matches a specific Daffodil Route type.
|
@@ -162,16 +169,13 @@ DaffExternalRouter.ctorParameters = () => [
|
|
162
169
|
* See {@link DaffRouteWithDataPath}
|
163
170
|
*/
|
164
171
|
const routeMatchesRouteType = (route, type) => { var _a; return ((_a = route === null || route === void 0 ? void 0 : route.data) === null || _a === void 0 ? void 0 : _a.daffExternalRouteType) === type; };
|
165
|
-
const ɵ0 = routeMatchesRouteType;
|
166
172
|
/**
|
167
173
|
* Adds a path to the `daffPaths` of the given route.
|
168
174
|
*
|
169
175
|
* See {@link DaffRouteWithDataPath}
|
170
176
|
*/
|
171
177
|
const addRouteToDaffPaths = (route, path) => route.data.daffPaths = Object.assign(Object.assign({}, route.data.daffPaths), { [path]: path });
|
172
|
-
const ɵ1 = addRouteToDaffPaths;
|
173
178
|
const operateOnRoute = (externalRoute) => (route) => addRouteToDaffPaths(route, externalRoute.path);
|
174
|
-
const ɵ2 = operateOnRoute;
|
175
179
|
/**
|
176
180
|
* Traverse the router config tree, halting after the first match.
|
177
181
|
* This traversal is implemented in a pre-order manner. As such, for large
|
@@ -197,7 +201,6 @@ const traverseRouteTree = (routes = [], matcher, operate) => {
|
|
197
201
|
}
|
198
202
|
return routes;
|
199
203
|
};
|
200
|
-
const ɵ3 = traverseRouteTree;
|
201
204
|
/**
|
202
205
|
* A route insertion strategy that can be used to append external routes onto
|
203
206
|
* existing Angular routes. This can be useful when you need to route to
|
@@ -277,5 +280,5 @@ const daffDataPathUrlMatcher = (segments, group, route) => {
|
|
277
280
|
* Generated bundle index. Do not edit.
|
278
281
|
*/
|
279
282
|
|
280
|
-
export { DAFF_EXTERNAL_ROUTER_CONFIG, DaffExternalRouter, DaffExternalRouterModule, DaffExternalRouterNoWildcardError, DaffExternalRouterUnknownRouteTypeError, daffDataPathUrlMatcher, daffInsertDataPathStrategy, daffInsertRouteBeforeWildCardStrategy, daffProvideRouteResolvableByType
|
281
|
-
//# sourceMappingURL=daffodil-external-router.
|
283
|
+
export { DAFF_EXTERNAL_ROUTER_CONFIG, DaffExternalRouter, DaffExternalRouterModule, DaffExternalRouterNoWildcardError, DaffExternalRouterUnknownRouteTypeError, daffDataPathUrlMatcher, daffInsertDataPathStrategy, daffInsertRouteBeforeWildCardStrategy, daffProvideRouteResolvableByType };
|
284
|
+
//# sourceMappingURL=daffodil-external-router.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"daffodil-external-router.mjs","sources":["../../../libs/external-router/src/config.ts","../../../libs/external-router/src/token/type-resolvable-routes.token.ts","../../../libs/external-router/src/external-router.module.ts","../../../libs/external-router/src/errors/no-wildcard.ts","../../../libs/external-router/src/errors/unknown-type.ts","../../../libs/external-router/src/transform/resolved-route-to-route.ts","../../../libs/external-router/src/router/strategies/insert-route-before-wildcard.ts","../../../libs/external-router/src/router/router.service.ts","../../../libs/external-router/src/router/strategies/insert-data-path.ts","../../../libs/external-router/src/router/url-matcher/data-path-matcher.ts","../../../libs/external-router/src/public_api.ts","../../../libs/external-router/src/daffodil-external-router.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nexport const daffExternalRouterConfigurationDefault: DaffExternalRouterConfiguration = {\n failedResolutionPath: '/',\n notFoundResolutionPath: '/',\n};\n\n/**\n * The token holding the runtime configuration for the behavior of the\n * `@daffodil/external-router` package.\n */\nexport const DAFF_EXTERNAL_ROUTER_CONFIG = new InjectionToken<\n\tDaffExternalRouterConfiguration\n>('DAFF_EXTERNAL_ROUTER_CONFIG', {\n providedIn: 'root',\n factory: () => daffExternalRouterConfigurationDefault,\n});\n\n/**\n * The configuration object for the external router package.\n */\nexport interface DaffExternalRouterConfiguration {\n\t/**\n\t * The path to redirect to when external route resolution fails.\n\t */\n\tfailedResolutionPath: string;\n\n\t/**\n\t * The path to redirect to when the requested URL is not found.\n\t */\n\tnotFoundResolutionPath: string;\n}\n","import {\n InjectionToken,\n Provider,\n} from '@angular/core';\n\nimport { DaffExternalRouterInsertionStrategy } from '../model/insertion-strategy.type';\nimport { DaffExternalRouteType } from '../model/route-type';\nimport { DaffRouteWithoutPath } from '../model/route-without-path';\nimport { DaffTypeRoutePair } from '../model/type-route-pair';\n\n/**\n * A multi-token that allows you to register route \"types\" that correspond to routes.\n */\nexport const DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE = new InjectionToken<\n\tDaffTypeRoutePair[]\n>('DAFF_EXTERNAL_ROUTER_RESOLVABLE_TYPE_ROUTES', {\n providedIn: 'root',\n factory: () => [],\n});\n\n/**\n * A provider used to connect a type to a route to enable dynamic route resolution at runtime.\n */\nexport function daffProvideRouteResolvableByType(typeRoutePair: DaffTypeRoutePair): Provider {\n return {\n provide: DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE,\n multi: true,\n useValue: typeRoutePair,\n };\n}\n\n/**\n * A multi-provider used to connect an array of types to their respective routes.\n */\nexport function daffProvideRoutesResolvableByType(routes: DaffTypeRoutePair[]): Provider[] {\n return routes.map((route: DaffTypeRoutePair) => ({\n provide: DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE,\n multi: true,\n useValue: route,\n }));\n}\n","import { CommonModule } from '@angular/common';\nimport {\n ModuleWithProviders,\n NgModule,\n} from '@angular/core';\n\nimport {\n DaffExternalRouterConfiguration,\n DAFF_EXTERNAL_ROUTER_CONFIG,\n daffExternalRouterConfigurationDefault,\n} from './config';\nimport { DaffTypeRoutePair } from './model/type-route-pair';\nimport { daffProvideRoutesResolvableByType } from './token/type-resolvable-routes.token';\n\n/**\n * The external `DaffExternalRouterModule` allows you to configure the\n * `@daffodil/external-router` package's behavior.\n */\n@NgModule({\n declarations: [],\n imports: [CommonModule],\n})\nexport class DaffExternalRouterModule {\n static forRoot(\n config: Partial<DaffExternalRouterConfiguration>,\n routes: DaffTypeRoutePair[] = [],\n ): ModuleWithProviders<DaffExternalRouterModule> {\n return {\n ngModule: DaffExternalRouterModule,\n providers: [\n { provide: DAFF_EXTERNAL_ROUTER_CONFIG, useValue: { ...daffExternalRouterConfigurationDefault, ...config }},\n ...daffProvideRoutesResolvableByType(routes),\n ],\n };\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\n/**\n * An error thrown when there was no wildcard route found in configuration\n * of the Angular Router.\n */\nexport class DaffExternalRouterNoWildcardError extends DaffInheritableError\n implements DaffError {\n\tpublic readonly code: string = 'NO_WILDCARD_ROUTE';\n\n\tconstructor(message?: string) {\n\t super(message);\n\t}\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\n/**\n * An error thrown when there is a failure matching a configured route to a\n * route type.\n */\nexport class DaffExternalRouterUnknownRouteTypeError extends DaffInheritableError\n implements DaffError {\n\tpublic readonly code: string = 'UNKNOWN_ROUTE_TYPE';\n\n\tconstructor(message?: string) {\n\t super(message);\n\t}\n}\n","import { DaffExternalRouterUnknownRouteTypeError } from '../errors/unknown-type';\nimport { DaffExternallyResolvableUrl } from '../model/resolvable-route';\nimport { DaffRouteInfo } from '../model/route-info';\nimport { DaffTypeRoutePair } from '../model/type-route-pair';\n\n/**\n * Transforms a DaffExternallyResolvableUrl into an Angular Route.\n */\nexport const daffTransformResolvedRouteToRoute = (\n resolvedRoute: DaffExternallyResolvableUrl,\n availableTypes: DaffTypeRoutePair[],\n): DaffRouteInfo => {\n const routeType = availableTypes\n .filter(t => t.type === resolvedRoute.type)\n .shift();\n if (!routeType) {\n throw new DaffExternalRouterUnknownRouteTypeError(\n `Unable to resolve the route '${resolvedRoute.url}'. Its type is '${resolvedRoute.type}' but a matching route wasn't found.`,\n );\n }\n\n return {\n route: {\n path: resolvedRoute.url,\n ...routeType.route,\n data: {\n daffExternalRouteType: resolvedRoute.type,\n ...routeType.route.data,\n },\n },\n insertionStrategy: routeType.insertionStrategy,\n };\n};\n","import {\n Route,\n Routes,\n} from '@angular/router';\n\nimport { DaffExternalRouterNoWildcardError } from '../../errors/no-wildcard';\nimport { DaffExternalRouterInsertionStrategy } from '../../model/insertion-strategy.type';\n\n/**\n * Inserts a Route into Routes right before the wildcard route.\n * If no wildcard is found, it fails fast with a `DaffExternalRouterNoWildcardError`.\n */\nexport const daffInsertRouteBeforeWildCardStrategy: DaffExternalRouterInsertionStrategy = (\n route: Route,\n routes: Routes,\n): Routes => {\n const index = routes.findIndex((r: Route) => r.path === '**');\n if (index === -1) {\n throw new DaffExternalRouterNoWildcardError(\n 'No wildcard (**) route was found during route resolution.',\n );\n }\n return [\n ...routes.slice(0, index),\n route,\n ...routes.slice(index),\n ];\n};\n","import {\n Inject,\n Injectable,\n} from '@angular/core';\nimport {\n Router,\n Route,\n} from '@angular/router';\n\n\nimport { DaffExternalRouterNoWildcardError } from '../errors/no-wildcard';\nimport { DaffExternallyResolvableUrl } from '../model/resolvable-route';\nimport { DaffTypeRoutePair } from '../model/type-route-pair';\nimport { DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE } from '../token/type-resolvable-routes.token';\nimport { daffTransformResolvedRouteToRoute } from '../transform/resolved-route-to-route';\nimport { daffInsertRouteBeforeWildCardStrategy } from './strategies/insert-route-before-wildcard';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffExternalRouter {\n constructor(\n private router: Router,\n @Inject(DAFF_EXTERNAL_ROUTER_ROUTES_RESOLVABLE_BY_TYPE)\n private runtimeRoutes: DaffTypeRoutePair[],\n ) { }\n\n /**\n * Adds a route to the existing router configuration.\n */\n add(resolvedRoute: DaffExternallyResolvableUrl) {\n //Get the route.\n const {\n route,\n insertionStrategy,\n } = daffTransformResolvedRouteToRoute(\n resolvedRoute,\n this.runtimeRoutes,\n );\n\n try {\n //Add it to configuration.\n this.router.config = (insertionStrategy || daffInsertRouteBeforeWildCardStrategy)(route, this.router.config);\n } catch (e) {\n if (e instanceof DaffExternalRouterNoWildcardError) {\n throw new DaffExternalRouterNoWildcardError(\n `${e.message} This usually means you have misconfigured your routes.`,\n );\n }\n\n throw e;\n }\n }\n}\n","import {\n Route,\n Routes,\n} from '@angular/router';\n\nimport { DaffExternalRouterInsertionStrategy } from '../../model/insertion-strategy.type';\nimport { DaffExternalRouteType } from '../../model/route-type';\nimport { DaffRouteWithDataPath } from '../../model/route-with-data-path';\n\n/**\n * Tests whether or not a route matches a specific Daffodil Route type.\n *\n * See {@link DaffRouteWithDataPath}\n */\nconst routeMatchesRouteType = (route: DaffRouteWithDataPath, type: DaffExternalRouteType): boolean => route?.data?.daffExternalRouteType === type;\n\n/**\n * Adds a path to the `daffPaths` of the given route.\n *\n * See {@link DaffRouteWithDataPath}\n */\nconst addRouteToDaffPaths:\n (route: DaffRouteWithDataPath, path: string) => Route =\n (route: DaffRouteWithDataPath, path: string) => route.data.daffPaths = {\n ...route.data.daffPaths,\n [path]: path,\n };\n\nconst operateOnRoute = (externalRoute: Route): (route: Route) => Route =>\n (route: DaffRouteWithDataPath) => addRouteToDaffPaths(route, externalRoute.path);\n\n/**\n * Traverse the router config tree, halting after the first match.\n * This traversal is implemented in a pre-order manner. As such, for large\n * configuration trees, it will be most efficient to place externally routed\n * components at the top of router configuration.\n */\nconst traverseRouteTree = (routes: Routes = [], matcher: (route: Route) => boolean, operate: (route: Route) => void): Routes => {\n if(routes.length === 0) {\n return routes;\n }\n\n const stack: Routes = [];\n const treeRoot = { children: routes };\n stack.push(treeRoot);\n\n while(stack.length) {\n const route = stack.pop();\n if(matcher(route)) {\n operate(route);\n break;\n }\n if(route.children){\n stack.push(...route.children.reverse());\n }\n }\n return routes;\n};\n\n/**\n * A route insertion strategy that can be used to append external routes onto\n * existing Angular routes. This can be useful when you need to route to\n * an existing lazy-loaded module from multiple externally defined urls.\n *\n * This should be used in combination with the {@link daffDataPathUrlMatcher} to match lazy-loaded modules with\n * associated external urls.\n *\n * For example, you can provide the insertion strategy in the {@link DaffExternalRouterModule} as below.\n *\n * ```ts\n * DaffExternalRouterModule.forRoot({}, [\n * {\n * type: 'CATEGORY',\n * insertionStrategy: daffInsertDataPathStrategy,\n * route: {}\n * }\n * ],\n * ```\n *\n * Then, you can match it with an associated route defined in your Routing\n * configuration with the {@link daffDataPathUrlMatcher}.\n *\n * ```ts\n * export const routes: Routes = [\n * {\n * matcher: daffDataPathUrlMatcher,\n * data: {\n * daffExternalRouteType: \"CATEGORY\",\n * },\n * loadChildren: () => import('./category/category.module').then((m) => m.MyCategoryModule),\n * }\n * ]\n * ```\n *\n * See {@link DaffRouteWithDataPath}\n *\n */\nexport const daffInsertDataPathStrategy: DaffExternalRouterInsertionStrategy = (externalRoute: DaffRouteWithDataPath, routes: Routes) => traverseRouteTree(\n routes,\n (route) => routeMatchesRouteType(route, externalRoute.data?.daffExternalRouteType),\n operateOnRoute(externalRoute),\n);\n","import {\n UrlMatcher,\n UrlSegment,\n UrlSegmentGroup,\n} from '@angular/router';\n\nimport { daffUriTruncateLeadingSlash } from '@daffodil/core/routing';\n\nimport { DaffRouteWithDataPath } from '../../model/public_api';\n\n/**\n * A UrlMatcher that does an exact match against a path stored in the special\n * configuration fields that External Router stores on a Route's data.\n *\n * ```ts\n * export const routes: Routes = [\n * {\n * matcher: daffDataPathUrlMatcher,\n * data: {\n * daffExternalRouteType: \"CATEGORY\",\n * },\n * loadChildren: () => import('./category/category.module').then((m) => m.ShopCategoryModule),\n * }\n * ]\n * ```\n * {@link daffInsertDataPathStrategy }\n * {@link DaffRouteWithDataPath }\n */\nexport const daffDataPathUrlMatcher: UrlMatcher = (segments: UrlSegment[], group: UrlSegmentGroup, route: DaffRouteWithDataPath) => {\n const path = daffUriTruncateLeadingSlash(segments.reduce((acc: string, segment) => acc + '/' + segment.path, ''));\n const paths = route?.data?.daffPaths;\n\n // If we don't have any paths, we can safely fail a match.\n if(!paths) {\n return null;\n }\n\n // Otherwise, look up the path in the dictionary, failing if a match isn't found,\n // but matching the entire segment if a match is found.\n return path in paths ? { consumed: segments } : null;\n};\n\n","/*\n * Public API Surface of @daffodil/external-router\n */\n\nexport { DaffExternalRouterModule } from './external-router.module';\n\nexport {\n DAFF_EXTERNAL_ROUTER_CONFIG,\n DaffExternalRouterConfiguration,\n} from './config';\n\nexport { daffProvideRouteResolvableByType } from './token/type-resolvable-routes.token';\n\nexport * from './model/public_api';\n\nexport { DaffExternalRouter } from './router/router.service';\nexport { daffInsertRouteBeforeWildCardStrategy } from './router/strategies/insert-route-before-wildcard';\n\nexport { daffInsertDataPathStrategy } from './router/strategies/insert-data-path';\nexport { daffDataPathUrlMatcher } from './router/url-matcher/data-path-matcher';\n\nexport { DaffExternalRouterNoWildcardError } from './errors/no-wildcard';\nexport { DaffExternalRouterUnknownRouteTypeError } from './errors/unknown-type';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;AAEO,MAAM,sCAAsC,GAAoC;AACrF,IAAA,oBAAoB,EAAE,GAAG;AACzB,IAAA,sBAAsB,EAAE,GAAG;CAC5B,CAAC;AAEF;;;AAGG;MACU,2BAA2B,GAAG,IAAI,cAAc,CAE3D,6BAA6B,EAAE;AAC/B,IAAA,UAAU,EAAE,MAAM;AAClB,IAAA,OAAO,EAAE,MAAM,sCAAsC;AACtD,CAAA;;ACND;;AAEG;AACI,MAAM,8CAA8C,GAAG,IAAI,cAAc,CAE9E,6CAA6C,EAAE;AAC/C,IAAA,UAAU,EAAE,MAAM;AAClB,IAAA,OAAO,EAAE,MAAM,EAAE;AAClB,CAAA,CAAC,CAAC;AAEH;;AAEG;AACG,SAAU,gCAAgC,CAAC,aAAgC,EAAA;IAC/E,OAAO;AACL,QAAA,OAAO,EAAE,8CAA8C;AACvD,QAAA,KAAK,EAAE,IAAI;AACX,QAAA,QAAQ,EAAE,aAAa;KACxB,CAAC;AACJ,C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AE,EAAE,CAAC,CAAC,CAAC;AAClH,IAAA,MAAM,KAAK,GAAG,CAAA,EAAA,GAAA,KAAK,KAAL,IAAA,IAAA,KAAK,KAAL,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,KAAK,CAAE,IAAI,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,SAAS,CAAC;;IAGrC,IAAG,CAAC,KAAK,EAAE;AACT,QAAA,OAAO,IAAI,CAAC;AACb,KAAA;;;AAID,IAAA,OAAO,IAAI,IAAI,KAAK,GAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;AACxD;;ACxCA;;AAEG;;ACFH;;AAEG;;;;"}
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import * as i0 from '@angular/core';
|
2
|
+
import { InjectionToken, Injectable, Inject, inject, NgModule } from '@angular/core';
|
3
|
+
import { of } from 'rxjs';
|
4
|
+
import { daffUriTruncateQueryFragment, daffUriTruncateLeadingSlash } from '@daffodil/core/routing';
|
5
|
+
import { DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION, DaffExternalRouterDriver } from '@daffodil/external-router/driver';
|
6
|
+
import { CommonModule } from '@angular/common';
|
7
|
+
|
8
|
+
const defaultConfig = {
|
9
|
+
resolver: () => DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION,
|
10
|
+
};
|
11
|
+
/**
|
12
|
+
* The token used by Daffodil to hold the driver's configuration.
|
13
|
+
*
|
14
|
+
* @docs-private
|
15
|
+
*/
|
16
|
+
const DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG = new InjectionToken('DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG', {
|
17
|
+
providedIn: 'root',
|
18
|
+
factory: () => defaultConfig,
|
19
|
+
});
|
20
|
+
|
21
|
+
/**
|
22
|
+
* The DaffExternalRouterInMemoryDriver is responsible for resolving
|
23
|
+
* a URL using the resolver in the provided configuration.
|
24
|
+
*
|
25
|
+
* @inheritdoc
|
26
|
+
*
|
27
|
+
* @see {@link DaffExternalRouterInMemoryDriver}
|
28
|
+
*/
|
29
|
+
class DaffExternalRouterInMemoryDriver {
|
30
|
+
constructor(configuration) {
|
31
|
+
this.configuration = configuration;
|
32
|
+
}
|
33
|
+
resolve(url) {
|
34
|
+
const truncatedUrl = daffUriTruncateQueryFragment(url);
|
35
|
+
const resolvedUrl = this.configuration.resolver(truncatedUrl);
|
36
|
+
return of(resolvedUrl?.url ? {
|
37
|
+
...resolvedUrl,
|
38
|
+
url: daffUriTruncateLeadingSlash(resolvedUrl.url),
|
39
|
+
} : DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterInMemoryDriver.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterInMemoryDriver, deps: [{ token: DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
|
43
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterInMemoryDriver.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterInMemoryDriver, providedIn: 'root' });
|
44
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterInMemoryDriver, decorators: [{
|
45
|
+
type: Injectable,
|
46
|
+
args: [{
|
47
|
+
providedIn: 'root',
|
48
|
+
}]
|
49
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
50
|
+
type: Inject,
|
51
|
+
args: [DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG]
|
52
|
+
}] }]; } });
|
53
|
+
|
54
|
+
/**
|
55
|
+
* The `DaffExternalRouterDriverInMemoryModule` is an importable NgModule that can
|
56
|
+
* be used to configure the {@link DaffExternalRouterInMemoryDriver}.
|
57
|
+
*/
|
58
|
+
class DaffExternalRouterDriverInMemoryModule {
|
59
|
+
static forRoot(config) {
|
60
|
+
return {
|
61
|
+
ngModule: DaffExternalRouterDriverInMemoryModule,
|
62
|
+
providers: [
|
63
|
+
{
|
64
|
+
provide: DaffExternalRouterDriver,
|
65
|
+
useExisting: DaffExternalRouterInMemoryDriver,
|
66
|
+
},
|
67
|
+
{
|
68
|
+
provide: DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG,
|
69
|
+
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
70
|
+
useFactory() {
|
71
|
+
return config instanceof InjectionToken ? inject(config) : config;
|
72
|
+
},
|
73
|
+
},
|
74
|
+
],
|
75
|
+
};
|
76
|
+
}
|
77
|
+
}
|
78
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterDriverInMemoryModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterDriverInMemoryModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
79
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterDriverInMemoryModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterDriverInMemoryModule, imports: [CommonModule] });
|
80
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterDriverInMemoryModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterDriverInMemoryModule, imports: [[CommonModule]] });
|
81
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterDriverInMemoryModule, decorators: [{
|
82
|
+
type: NgModule,
|
83
|
+
args: [{
|
84
|
+
declarations: [],
|
85
|
+
imports: [CommonModule],
|
86
|
+
}]
|
87
|
+
}] });
|
88
|
+
|
89
|
+
/*
|
90
|
+
* Public API Surface of @daffodil/external-router/driver/in-memory
|
91
|
+
*/
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Generated bundle index. Do not edit.
|
95
|
+
*/
|
96
|
+
|
97
|
+
export { DaffExternalRouterDriverInMemoryModule, DaffExternalRouterInMemoryDriver };
|
98
|
+
//# sourceMappingURL=daffodil-external-router-driver-in-memory.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"daffodil-external-router-driver-in-memory.mjs","sources":["../../../libs/external-router/driver/in-memory/src/config.ts","../../../libs/external-router/driver/in-memory/src/in-memory.service.ts","../../../libs/external-router/driver/in-memory/src/in-memory.module.ts","../../../libs/external-router/driver/in-memory/src/public_api.ts","../../../libs/external-router/driver/in-memory/src/daffodil-external-router-driver-in-memory.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nimport { DaffExternallyResolvableUrl } from '@daffodil/external-router';\nimport { DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION } from '@daffodil/external-router/driver';\n\n/**\n * A lookup for a URL.\n * Returns an {@link DaffExternallyResolvableUrl} or\n * {@link DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION} if the URL cannot be resolved\n */\nexport type DaffExternalRouterDriverInMemoryResolver = (url: string) => DaffExternallyResolvableUrl;\n\n/**\n * The configuration for the in-memory driver.\n */\nexport interface DaffExternalRouterDriverInMemoryConfig {\n\tresolver: DaffExternalRouterDriverInMemoryResolver;\n}\n\nconst defaultConfig: DaffExternalRouterDriverInMemoryConfig = {\n resolver: () => DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION,\n};\n\n/**\n * The token used by Daffodil to hold the driver's configuration.\n *\n * @docs-private\n */\nexport const DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG = new InjectionToken<\n\tDaffExternalRouterDriverInMemoryConfig\n>('DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG', {\n providedIn: 'root',\n factory: () => defaultConfig,\n});\n","import {\n Injectable,\n Inject,\n} from '@angular/core';\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 DaffExternalRouterDriverInterface,\n DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION,\n} from '@daffodil/external-router/driver';\n\nimport {\n DaffExternalRouterDriverInMemoryConfig,\n DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG,\n} from './config';\n\n/**\n * The DaffExternalRouterInMemoryDriver is responsible for resolving\n * a URL using the resolver in the provided configuration.\n *\n * @inheritdoc\n *\n * @see {@link DaffExternalRouterInMemoryDriver}\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffExternalRouterInMemoryDriver\nimplements DaffExternalRouterDriverInterface {\n constructor(\n\t\t@Inject(DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG)\n\t\tprivate configuration: DaffExternalRouterDriverInMemoryConfig,\n ) {}\n\n resolve(url: string): Observable<DaffExternallyResolvableUrl> {\n const truncatedUrl = daffUriTruncateQueryFragment(url);\n const resolvedUrl = this.configuration.resolver(truncatedUrl);\n\n return of(resolvedUrl?.url ? {\n ...resolvedUrl,\n url: daffUriTruncateLeadingSlash(resolvedUrl.url),\n } : DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION);\n }\n}\n","import { CommonModule } from '@angular/common';\nimport {\n NgModule,\n ModuleWithProviders,\n InjectionToken,\n inject,\n} from '@angular/core';\n\nimport { DaffExternalRouterDriver } from '@daffodil/external-router/driver';\n\nimport {\n DaffExternalRouterDriverInMemoryConfig,\n DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG,\n} from './config';\nimport { DaffExternalRouterInMemoryDriver } from './in-memory.service';\n\n/**\n * The `DaffExternalRouterDriverInMemoryModule` is an importable NgModule that can\n * be used to configure the {@link DaffExternalRouterInMemoryDriver}.\n */\n@NgModule({\n declarations: [],\n imports: [CommonModule],\n})\nexport class DaffExternalRouterDriverInMemoryModule {\n static forRoot(\n config: DaffExternalRouterDriverInMemoryConfig | InjectionToken<DaffExternalRouterDriverInMemoryConfig>,\n ): ModuleWithProviders<DaffExternalRouterDriverInMemoryModule> {\n return {\n ngModule: DaffExternalRouterDriverInMemoryModule,\n providers: [\n {\n provide: DaffExternalRouterDriver,\n useExisting: DaffExternalRouterInMemoryDriver,\n },\n {\n provide: DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG,\n // eslint-disable-next-line prefer-arrow/prefer-arrow-functions\n useFactory() {\n return config instanceof InjectionToken ? inject(config) : config;\n },\n },\n ],\n };\n }\n}\n","/*\n * Public API Surface of @daffodil/external-router/driver/in-memory\n */\n\nexport { DaffExternalRouterInMemoryDriver } from './in-memory.service';\nexport { DaffExternalRouterDriverInMemoryModule } from './in-memory.module';\n\nexport {\n DaffExternalRouterDriverInMemoryConfig,\n DaffExternalRouterDriverInMemoryResolver,\n} from './config';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAmBA,MAAM,aAAa,GAA2C;AAC5D,IAAA,QAAQ,EAAE,MAAM,yCAAyC;CAC1D,CAAC;AAEF;;;;AAIG;AACI,MAAM,4CAA4C,GAAG,IAAI,cAAc,CAE5E,8CAA8C,EAAE;AAChD,IAAA,UAAU,EAAE,MAAM;AAClB,IAAA,OAAO,EAAE,MAAM,aAAa;AAC7B,CAAA,CAAC;;ACTF;;;;;;;AAOG;MAIU,gCAAgC,CAAA;AAE3C,IAAA,WAAA,CAEQ,aAAqD,EAAA;QAArD,IAAa,CAAA,aAAA,GAAb,aAAa,CAAwC;KACzD;AAEJ,IAAA,OAAO,CAAC,GAAW,EAA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AA4C;;oBAErD,UAAU,GAAA;AACR,wBAAA,OAAO,MAAM,YAAY,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;qBACnE;AACF,iBAAA;AACF,aAAA;SACF,CAAC;KACH;;yKApBU,sCAAsC,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;AAAtC,sCAAA,sCAAA,CAAA,IAAA,GAAA,EAAA,CAAA,mBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,sCAAsC,YAFvC,YAAY,CAAA,EAAA,CAAA,CAAA;0KAEX,sCAAsC,EAAA,OAAA,EAAA,CAFxC,CAAC,YAAY,CAAC,CAAA,EAAA,CAAA,CAAA;2FAEZ,sCAAsC,EAAA,UAAA,EAAA,CAAA;kBAJlD,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,YAAY,EAAE,EAAE;oBAChB,OAAO,EAAE,CAAC,YAAY,CAAC;AACxB,iBAAA,CAAA;;;ACvBD;;AAEG;;ACFH;;AAEG;;;;"}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
import * as i0 from '@angular/core';
|
2
|
+
import { Injectable, NgModule } from '@angular/core';
|
3
|
+
import * as i1 from 'apollo-angular';
|
4
|
+
import { gql } from 'apollo-angular';
|
5
|
+
import { map } from 'rxjs/operators';
|
6
|
+
import { daffUriTruncateLeadingSlash, daffUriTruncateQueryFragment } from '@daffodil/core/routing';
|
7
|
+
import { DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION, DaffExternalRouterDriver } from '@daffodil/external-router/driver';
|
8
|
+
import { magentoTransformRedirectToHttpCode } from '@daffodil/external-router/driver/magento';
|
9
|
+
import { CommonModule } from '@angular/common';
|
10
|
+
import { DAFF_MAGENTO_CACHEABLE_OPERATIONS } from '@daffodil/driver/magento';
|
11
|
+
|
12
|
+
const DAFF_MAGENTO_RESOLVE_URL_QUERY_NAME = 'MagentoResolveUrlv241';
|
13
|
+
/**
|
14
|
+
* This query retrieves a URL resolution from Magento and informs you about
|
15
|
+
* what type of route the URL is.
|
16
|
+
*/
|
17
|
+
const MagentoResolveUrlv241 = gql `
|
18
|
+
query ${DAFF_MAGENTO_RESOLVE_URL_QUERY_NAME}($url: String!) {
|
19
|
+
urlResolver(url: $url) {
|
20
|
+
id
|
21
|
+
relative_url
|
22
|
+
redirectCode
|
23
|
+
type
|
24
|
+
}
|
25
|
+
}
|
26
|
+
`;
|
27
|
+
|
28
|
+
const transformResolutionToResolvableUrlv241 = (resolution) => (resolution ? {
|
29
|
+
id: resolution.id?.toString(),
|
30
|
+
url: daffUriTruncateLeadingSlash(daffUriTruncateQueryFragment(resolution.relative_url)),
|
31
|
+
type: resolution.type,
|
32
|
+
code: magentoTransformRedirectToHttpCode(resolution.redirectCode),
|
33
|
+
} : DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION);
|
34
|
+
|
35
|
+
/**
|
36
|
+
* The DaffExternalRouterMagentoDriver is responsible for translating an
|
37
|
+
* arbitrary URI into a DaffExternallyResolvableUrl with Magento environments.
|
38
|
+
*
|
39
|
+
* @inheritdoc
|
40
|
+
*/
|
41
|
+
class DaffExternalRouterMagentoDriver {
|
42
|
+
constructor(apollo) {
|
43
|
+
this.apollo = apollo;
|
44
|
+
}
|
45
|
+
resolve(url) {
|
46
|
+
return this.apollo
|
47
|
+
.query({
|
48
|
+
query: MagentoResolveUrlv241,
|
49
|
+
variables: {
|
50
|
+
url: daffUriTruncateQueryFragment(url),
|
51
|
+
},
|
52
|
+
})
|
53
|
+
.pipe(map(response => transformResolutionToResolvableUrlv241(response.data.urlResolver)));
|
54
|
+
}
|
55
|
+
}
|
56
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterMagentoDriver.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterMagentoDriver, deps: [{ token: i1.Apollo }], target: i0.ɵɵFactoryTarget.Injectable });
|
57
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterMagentoDriver.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterMagentoDriver, providedIn: 'root' });
|
58
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterMagentoDriver, decorators: [{
|
59
|
+
type: Injectable,
|
60
|
+
args: [{
|
61
|
+
providedIn: 'root',
|
62
|
+
}]
|
63
|
+
}], ctorParameters: function () { return [{ type: i1.Apollo }]; } });
|
64
|
+
|
65
|
+
/**
|
66
|
+
* The module used to configure the {@link DaffExternalRouterDriver} for usage with Magento.
|
67
|
+
*
|
68
|
+
* ```ts
|
69
|
+
* @NgModule({
|
70
|
+
* declarations: [],
|
71
|
+
* imports: [
|
72
|
+
* ...
|
73
|
+
* DaffExternalRouterDriverMagentoModule.forRoot()
|
74
|
+
* ],
|
75
|
+
* })
|
76
|
+
* export class AppModule{}
|
77
|
+
* ```
|
78
|
+
*
|
79
|
+
* Note that this package depends upon ApolloClient, as the Magento driver uses GraphQl to make it's API calls.
|
80
|
+
*/
|
81
|
+
class DaffExternalRouterDriverMagentoModule {
|
82
|
+
/**
|
83
|
+
* Configures the package for the root injector.
|
84
|
+
*/
|
85
|
+
static forRoot() {
|
86
|
+
return {
|
87
|
+
ngModule: DaffExternalRouterDriverMagentoModule,
|
88
|
+
providers: [
|
89
|
+
{
|
90
|
+
provide: DaffExternalRouterDriver,
|
91
|
+
useExisting: DaffExternalRouterMagentoDriver,
|
92
|
+
},
|
93
|
+
{
|
94
|
+
provide: DAFF_MAGENTO_CACHEABLE_OPERATIONS,
|
95
|
+
useValue: DAFF_MAGENTO_RESOLVE_URL_QUERY_NAME,
|
96
|
+
multi: true,
|
97
|
+
},
|
98
|
+
],
|
99
|
+
};
|
100
|
+
}
|
101
|
+
}
|
102
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterDriverMagentoModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterDriverMagentoModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
103
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterDriverMagentoModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterDriverMagentoModule, imports: [CommonModule] });
|
104
|
+
/** @nocollapse */ /** @nocollapse */ DaffExternalRouterDriverMagentoModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterDriverMagentoModule, imports: [[CommonModule]] });
|
105
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffExternalRouterDriverMagentoModule, decorators: [{
|
106
|
+
type: NgModule,
|
107
|
+
args: [{
|
108
|
+
declarations: [],
|
109
|
+
imports: [CommonModule],
|
110
|
+
}]
|
111
|
+
}] });
|
112
|
+
|
113
|
+
/*
|
114
|
+
* Public API Surface of @daffodil/external-router/driver/magento/2.4.1
|
115
|
+
*/
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Generated bundle index. Do not edit.
|
119
|
+
*/
|
120
|
+
|
121
|
+
export { DaffExternalRouterDriverMagentoModule, DaffExternalRouterMagentoDriver };
|
122
|
+
//# sourceMappingURL=daffodil-external-router-driver-magento-2.4.1.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"daffodil-external-router-driver-magento-2.4.1.mjs","sources":["../../../libs/external-router/driver/magento/2.4.1/src/graphql/queries/resolve-url-v2.4.1.ts","../../../libs/external-router/driver/magento/2.4.1/src/transforms/resolution-to-resolvable-url.ts","../../../libs/external-router/driver/magento/2.4.1/src/magento.service.ts","../../../libs/external-router/driver/magento/2.4.1/src/magento.module.ts","../../../libs/external-router/driver/magento/2.4.1/src/public_api.ts","../../../libs/external-router/driver/magento/2.4.1/src/daffodil-external-router-driver-magento-2.4.1.ts"],"sourcesContent":["import { gql } from 'apollo-angular';\n\nexport const DAFF_MAGENTO_RESOLVE_URL_QUERY_NAME = 'MagentoResolveUrlv241';\n\n/**\n * This query retrieves a URL resolution from Magento and informs you about\n * what type of route the URL is.\n */\nexport const MagentoResolveUrlv241 = gql`\n\tquery ${DAFF_MAGENTO_RESOLVE_URL_QUERY_NAME}($url: String!) {\n\t\turlResolver(url: $url) {\n\t\t\tid\n\t\t\trelative_url\n\t\t\tredirectCode\n\t\t\ttype\n\t\t}\n\t}\n`;\n","import {\n daffUriTruncateLeadingSlash,\n daffUriTruncateQueryFragment,\n} from '@daffodil/core/routing';\nimport { DaffExternallyResolvableUrl } from '@daffodil/external-router';\nimport { DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION } from '@daffodil/external-router/driver';\nimport {\n MagentoUrlResolver,\n magentoTransformRedirectToHttpCode,\n} from '@daffodil/external-router/driver/magento';\n\nexport const transformResolutionToResolvableUrlv241 = (\n resolution: MagentoUrlResolver,\n): DaffExternallyResolvableUrl => (resolution ? {\n id: resolution.id?.toString(),\n url: daffUriTruncateLeadingSlash(daffUriTruncateQueryFragment(resolution.relative_url)),\n type: resolution.type,\n code: magentoTransformRedirectToHttpCode(resolution.redirectCode),\n} : DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION);\n\n","import {\n Injectable,\n Inject,\n} from '@angular/core';\nimport { Apollo } from 'apollo-angular';\nimport { Observable } from 'rxjs';\nimport { map } from 'rxjs/operators';\n\nimport { daffUriTruncateQueryFragment } from '@daffodil/core/routing';\nimport { DaffExternallyResolvableUrl } from '@daffodil/external-router';\nimport { DaffExternalRouterDriverInterface } from '@daffodil/external-router/driver';\nimport { MagentoUrlResolverResponse } from '@daffodil/external-router/driver/magento';\n\nimport { MagentoResolveUrlv241 } from './graphql/queries/resolve-url-v2.4.1';\nimport { transformResolutionToResolvableUrlv241 } from './transforms/resolution-to-resolvable-url';\n\n/**\n * The DaffExternalRouterMagentoDriver is responsible for translating an\n * arbitrary URI into a DaffExternallyResolvableUrl with Magento environments.\n *\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffExternalRouterMagentoDriver\nimplements DaffExternalRouterDriverInterface {\n constructor(private apollo: Apollo) {}\n\n resolve(url: string): Observable<DaffExternallyResolvableUrl> {\n return this.apollo\n .query<MagentoUrlResolverResponse>({\n query: MagentoResolveUrlv241,\n variables: {\n url: daffUriTruncateQueryFragment(url),\n },\n })\n .pipe(map(response => transformResolutionToResolvableUrlv241(response.data.urlResolver)));\n }\n}\n","import { CommonModule } from '@angular/common';\nimport {\n NgModule,\n ModuleWithProviders,\n} from '@angular/core';\n\nimport { DAFF_MAGENTO_CACHEABLE_OPERATIONS } from '@daffodil/driver/magento';\nimport { DaffExternalRouterDriver } from '@daffodil/external-router/driver';\n\nimport { DAFF_MAGENTO_RESOLVE_URL_QUERY_NAME } from './graphql/queries/resolve-url-v2.4.1';\nimport { DaffExternalRouterMagentoDriver } from './magento.service';\n/**\n * The module used to configure the {@link DaffExternalRouterDriver} for usage with Magento.\n *\n * ```ts\n * @NgModule({\n * declarations: [],\n * imports: [\n * ...\n * DaffExternalRouterDriverMagentoModule.forRoot()\n * ],\n * })\n * export class AppModule{}\n * ```\n *\n * Note that this package depends upon ApolloClient, as the Magento driver uses GraphQl to make it's API calls.\n */\n@NgModule({\n declarations: [],\n imports: [CommonModule],\n})\nexport class DaffExternalRouterDriverMagentoModule {\n\n /**\n * Configures the package for the root injector.\n */\n static forRoot(): ModuleWithProviders<DaffExternalRouterDriverMagentoModule> {\n return {\n ngModule: DaffExternalRouterDriverMagentoModule,\n providers: [\n {\n provide: DaffExternalRouterDriver,\n useExisting: DaffExternalRouterMagentoDriver,\n },\n {\n provide: DAFF_MAGENTO_CACHEABLE_OPERATIONS,\n useValue: DAFF_MAGENTO_RESOLVE_URL_QUERY_NAME,\n multi: true,\n },\n ],\n };\n }\n}\n","/*\n * Public API Surface of @daffodil/external-router/driver/magento/2.4.1\n */\n\nexport { DaffExternalRouterMagentoDriver } from './magento.service';\nexport { DaffExternalRouterDriverMagentoModule } from './magento.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;AAEO,MAAM,mCAAmC,GAAG,uBAAuB,CAAC;AAE3E;;;AAGG;AACI,MAAM,qBAAqB,GAAG,GAAG,CAAA,CAAA;SAC/B,mCAAmC,CAAA;;;;;;;;CAQ3C;;ACNM,MAAM,sCAAsC,GAAG,CACpD,UAA8B,MACG,UAAU,GAAG;AAC9C,IAAA,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE;IAC7B,GAAG,EAAE,2BAA2B,CAAC,4BAA4B,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACvF,IAAI,EAAE,UAAU,CAAC,IAAI;AACrB,IAAA,IAAI,EAAE,kCAAkC,CAAC,UAAU,CAAC,YAAY,CAAC;AAClE,CAAA,GAAG,yCAAyC,CAAC;;ACF9C;;;;;AAKG;MAIU,+BAA+B,CAAA;AAE1C,IAAA,WAAA,CAAoB,MAAc,EAAA;QAAd,IAAM,CAAA,MAAA,GAAN,MAAM,CAAQ;KAAI;AAEtC,IAAA,OAAO,CAAC,GAAW,EAAA;QACjB,OAAO,IAAI,CAAC,MAAM;AACf,aAAA,KAAK,CAA6B;AACjC,YAAA,KAAK,EAAE,qBAAqB;AAC5B,YAAA,SAAS,EAAE;AACT,gBAAA,GAAG,EAAE,4BAA4B,CAAC,GAAG,CAAC;AACvC,aAAA;SACF,CAAC;AACD,aAAA,IAAI,CAAC,GAAG,CAAC,QAAQ,IAAI,sCAAsC,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC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