@nascentdigital/funnel-engine 4.4.18

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.
Files changed (88) hide show
  1. package/dist/LeadGen.d.ts +10 -0
  2. package/dist/LeadGen.js +51 -0
  3. package/dist/LeadGen.js.map +1 -0
  4. package/dist/RegionalSite.d.ts +31 -0
  5. package/dist/RegionalSite.js +79 -0
  6. package/dist/RegionalSite.js.map +1 -0
  7. package/dist/Site.d.ts +39 -0
  8. package/dist/Site.js +148 -0
  9. package/dist/Site.js.map +1 -0
  10. package/dist/SiteAuth.d.ts +19 -0
  11. package/dist/SiteAuth.js +103 -0
  12. package/dist/SiteAuth.js.map +1 -0
  13. package/dist/SiteContent.d.ts +45 -0
  14. package/dist/SiteContent.js +152 -0
  15. package/dist/SiteContent.js.map +1 -0
  16. package/dist/SiteEngine.d.ts +8 -0
  17. package/dist/SiteEngine.js +92 -0
  18. package/dist/SiteEngine.js.map +1 -0
  19. package/dist/SiteLayout.d.ts +49 -0
  20. package/dist/SiteLayout.js +80 -0
  21. package/dist/SiteLayout.js.map +1 -0
  22. package/dist/Sitemap.d.ts +4 -0
  23. package/dist/Sitemap.js +88 -0
  24. package/dist/Sitemap.js.map +1 -0
  25. package/dist/client.d.ts +2 -0
  26. package/dist/client.js +10 -0
  27. package/dist/client.js.map +1 -0
  28. package/dist/config/EditorConfig.d.ts +14 -0
  29. package/dist/config/EditorConfig.js +3 -0
  30. package/dist/config/EditorConfig.js.map +1 -0
  31. package/dist/config/NextConfig.d.ts +7 -0
  32. package/dist/config/NextConfig.js +3 -0
  33. package/dist/config/NextConfig.js.map +1 -0
  34. package/dist/config/ServerConfig.d.ts +12 -0
  35. package/dist/config/ServerConfig.js +35 -0
  36. package/dist/config/ServerConfig.js.map +1 -0
  37. package/dist/config/SiteConfig.d.ts +11 -0
  38. package/dist/config/SiteConfig.js +69 -0
  39. package/dist/config/SiteConfig.js.map +1 -0
  40. package/dist/config/index.d.ts +4 -0
  41. package/dist/config/index.js +21 -0
  42. package/dist/config/index.js.map +1 -0
  43. package/dist/content/Regionalization.d.ts +10 -0
  44. package/dist/content/Regionalization.js +22 -0
  45. package/dist/content/Regionalization.js.map +1 -0
  46. package/dist/content/index.d.ts +1 -0
  47. package/dist/content/index.js +18 -0
  48. package/dist/content/index.js.map +1 -0
  49. package/dist/forms/FormApi.d.ts +6 -0
  50. package/dist/forms/FormApi.js +34 -0
  51. package/dist/forms/FormApi.js.map +1 -0
  52. package/dist/forms/index.d.ts +1 -0
  53. package/dist/forms/index.js +18 -0
  54. package/dist/forms/index.js.map +1 -0
  55. package/dist/index.d.ts +12 -0
  56. package/dist/index.js +29 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/middleware/MiddlewarePriority.d.ts +4 -0
  59. package/dist/middleware/MiddlewarePriority.js +9 -0
  60. package/dist/middleware/MiddlewarePriority.js.map +1 -0
  61. package/dist/middleware/SiteMiddleware.d.ts +12 -0
  62. package/dist/middleware/SiteMiddleware.js +11 -0
  63. package/dist/middleware/SiteMiddleware.js.map +1 -0
  64. package/dist/middleware/SiteResponse.d.ts +23 -0
  65. package/dist/middleware/SiteResponse.js +133 -0
  66. package/dist/middleware/SiteResponse.js.map +1 -0
  67. package/dist/middleware/index.d.ts +4 -0
  68. package/dist/middleware/index.js +21 -0
  69. package/dist/middleware/index.js.map +1 -0
  70. package/dist/middleware/regionalization/RegionalizationMiddleware.d.ts +22 -0
  71. package/dist/middleware/regionalization/RegionalizationMiddleware.js +117 -0
  72. package/dist/middleware/regionalization/RegionalizationMiddleware.js.map +1 -0
  73. package/dist/middleware/regionalization/index.d.ts +1 -0
  74. package/dist/middleware/regionalization/index.js +18 -0
  75. package/dist/middleware/regionalization/index.js.map +1 -0
  76. package/dist/middleware/regionalization/specs/RegionalizationMiddleware.spec.d.ts +1 -0
  77. package/dist/middleware/regionalization/specs/RegionalizationMiddleware.spec.js +44 -0
  78. package/dist/middleware/regionalization/specs/RegionalizationMiddleware.spec.js.map +1 -0
  79. package/dist/query/getPages.d.ts +14 -0
  80. package/dist/query/getPages.js +22 -0
  81. package/dist/query/getPages.js.map +1 -0
  82. package/dist/query/getPreviews.d.ts +16 -0
  83. package/dist/query/getPreviews.js +38 -0
  84. package/dist/query/getPreviews.js.map +1 -0
  85. package/dist/query/index.d.ts +2 -0
  86. package/dist/query/index.js +19 -0
  87. package/dist/query/index.js.map +1 -0
  88. package/package.json +49 -0
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.SiteConfig = void 0;
15
+ // namespace
16
+ var SiteConfig;
17
+ (function (SiteConfig) {
18
+ // methods
19
+ function create(_a = {}) {
20
+ var { optimizePackageImports = [], remotePatterns = [], unoptimizedImages = false, rewrites, redirects } = _a, config = __rest(_a, ["optimizePackageImports", "remotePatterns", "unoptimizedImages", "rewrites", "redirects"]);
21
+ return Object.assign(Object.assign({}, config), { webpack: config => {
22
+ config.module.exprContextCritical = false;
23
+ return config;
24
+ }, outputFileTracingIncludes: {
25
+ '/*': [
26
+ '../node_modules/@nascentdigital/**/*'
27
+ ]
28
+ }, poweredByHeader: false, eslint: {
29
+ ignoreDuringBuilds: true
30
+ }, typescript: {
31
+ ignoreBuildErrors: true
32
+ }, experimental: {
33
+ optimizePackageImports: [
34
+ '@nascentdigital/funnel-apps',
35
+ '@nascentdigital/funnel-cms',
36
+ '@nascentdigital/funnel-core',
37
+ '@nascentdigital/funnel-editor',
38
+ '@nascentdigital/funnel-engine',
39
+ '@nascentdigital/funnel-services',
40
+ '@nascentdigital/funnel-ui',
41
+ 'react-router',
42
+ 'zod',
43
+ ...optimizePackageImports
44
+ ],
45
+ esmExternals: 'loose'
46
+ }, reactStrictMode: false, images: {
47
+ remotePatterns: [
48
+ // TODO: drop this for non-prod environments
49
+ {
50
+ protocol: 'http',
51
+ hostname: 'localhost'
52
+ },
53
+ {
54
+ protocol: 'https',
55
+ hostname: 'images.ctfassets.net'
56
+ },
57
+ {
58
+ protocol: 'https',
59
+ hostname: '*.media.strapiapp.com'
60
+ },
61
+ ...remotePatterns
62
+ ],
63
+ unoptimized: unoptimizedImages
64
+ }, redirects,
65
+ rewrites });
66
+ }
67
+ SiteConfig.create = create;
68
+ })(SiteConfig || (exports.SiteConfig = SiteConfig = {}));
69
+ //# sourceMappingURL=SiteConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SiteConfig.js","sourceRoot":"","sources":["../../src/config/SiteConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAGA,YAAY;AACZ,IAAiB,UAAU,CAuF1B;AAvFD,WAAiB,UAAU;IAmBzB,UAAU;IACV,SAAgB,MAAM,CAAC,KAOA,EAAE;YAPF,EACrB,sBAAsB,GAAG,EAAE,EAC3B,cAAc,GAAG,EAAE,EACnB,iBAAiB,GAAG,KAAK,EACzB,QAAQ,EACR,SAAS,OAEc,EADpB,MAAM,cANY,0FAOtB,CADU;QAET,uCACK,MAAM,KACT,OAAO,EAAE,MAAM,CAAC,EAAE;gBAChB,MAAM,CAAC,MAAM,CAAC,mBAAmB,GAAG,KAAK,CAAA;gBACzC,OAAO,MAAM,CAAA;YACf,CAAC,EACD,yBAAyB,EAAE;gBACzB,IAAI,EAAE;oBACJ,sCAAsC;iBACvC;aACF,EACD,eAAe,EAAE,KAAK,EACtB,MAAM,EAAE;gBACN,kBAAkB,EAAE,IAAI;aACzB,EAED,UAAU,EAAE;gBACV,iBAAiB,EAAE,IAAI;aACxB,EACD,YAAY,EAAE;gBACZ,sBAAsB,EAAE;oBACtB,6BAA6B;oBAC7B,4BAA4B;oBAC5B,6BAA6B;oBAC7B,+BAA+B;oBAC/B,+BAA+B;oBAC/B,iCAAiC;oBACjC,2BAA2B;oBAC3B,cAAc;oBACd,KAAK;oBACL,GAAG,sBAAsB;iBAC1B;gBAED,YAAY,EAAE,OAAO;aACtB,EACD,eAAe,EAAE,KAAK,EACtB,MAAM,EAAE;gBACN,cAAc,EAAE;oBACd,4CAA4C;oBAC5C;wBACE,QAAQ,EAAE,MAAM;wBAChB,QAAQ,EAAE,WAAW;qBACtB;oBACD;wBACE,QAAQ,EAAE,OAAO;wBACjB,QAAQ,EAAE,sBAAsB;qBACjC;oBACD;wBACE,QAAQ,EAAE,OAAO;wBACjB,QAAQ,EAAE,uBAAuB;qBAClC;oBACD,GAAG,cAAc;iBAClB;gBACD,WAAW,EAAE,iBAAiB;aAC/B,EACD,SAAS;YACT,QAAQ,IACT;IACH,CAAC;IAlEe,iBAAM,SAkErB,CAAA;AACH,CAAC,EAvFgB,UAAU,0BAAV,UAAU,QAuF1B"}
@@ -0,0 +1,4 @@
1
+ export * from './EditorConfig';
2
+ export * from './NextConfig';
3
+ export * from './ServerConfig';
4
+ export * from './SiteConfig';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./EditorConfig"), exports);
18
+ __exportStar(require("./NextConfig"), exports);
19
+ __exportStar(require("./ServerConfig"), exports);
20
+ __exportStar(require("./SiteConfig"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,+CAA4B;AAC5B,iDAA8B;AAC9B,+CAA4B"}
@@ -0,0 +1,10 @@
1
+ import { Language, Locale } from '@nascentdigital/funnel-core';
2
+ export declare class Regionalization<TRegion extends string = string> {
3
+ readonly data: Regionalization.Data<TRegion>;
4
+ constructor(data: Regionalization.Data<TRegion>);
5
+ localeParams(): Locale.Params<TRegion>[];
6
+ }
7
+ export declare namespace Regionalization {
8
+ type Data<TRegion extends string = string> = Record<TRegion, Localization>;
9
+ type Localization = Partial<Record<Language, string[]>>;
10
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Regionalization = void 0;
4
+ // class
5
+ class Regionalization {
6
+ constructor(data) {
7
+ this.data = data;
8
+ }
9
+ localeParams() {
10
+ return Object.entries(this.data).reduce((params, [region, localization]) => {
11
+ // simplify locales
12
+ Object.keys(localization).forEach(language => params.push({
13
+ region: region,
14
+ language: language
15
+ }));
16
+ // keep reducing
17
+ return params;
18
+ }, []);
19
+ }
20
+ }
21
+ exports.Regionalization = Regionalization;
22
+ //# sourceMappingURL=Regionalization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Regionalization.js","sourceRoot":"","sources":["../../src/content/Regionalization.ts"],"names":[],"mappings":";;;AAGA,QAAQ;AACR,MAAa,eAAe;IAE1B,YACkB,IAAmC;QAAnC,SAAI,GAAJ,IAAI,CAA+B;IAErD,CAAC;IAEM,YAAY;QACjB,OAAO,MAAM,CAAC,OAAO,CAA+B,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,EAAE;YAEvG,mBAAmB;YACnB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;gBACxD,MAAM,EAAE,MAAiB;gBACzB,QAAQ,EAAE,QAAoB;aAC/B,CAAC,CAAC,CAAA;YAEH,gBAAgB;YAChB,OAAO,MAAM,CAAA;QACf,CAAC,EAAE,EAA8B,CAAC,CAAA;IACpC,CAAC;CACF;AApBD,0CAoBC"}
@@ -0,0 +1 @@
1
+ export * from './Regionalization';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Regionalization"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/content/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC"}
@@ -0,0 +1,6 @@
1
+ import type { NextRequest, NextResponse as NextResponseType } from 'next/server';
2
+ export declare namespace FormApi {
3
+ function process(request: NextRequest, NextResponse: typeof NextResponseType): Promise<NextResponseType<{
4
+ error: import("@nascentdigital/funnel-core").SerializedIsometricError;
5
+ }> | undefined>;
6
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FormApi = void 0;
4
+ const funnel_core_1 = require("@nascentdigital/funnel-core");
5
+ // namespace
6
+ var FormApi;
7
+ (function (FormApi) {
8
+ // methods
9
+ async function process(request, NextResponse) {
10
+ // handle request
11
+ try {
12
+ // process request
13
+ console.debug('[FormApi] handling request', request);
14
+ }
15
+ // or return error on failure
16
+ catch (e) {
17
+ console.error('[FormApi] caught error processing request', e);
18
+ // handle API error
19
+ if (e instanceof funnel_core_1.ApiError) {
20
+ return NextResponse.json({ error: e.serialize() }, { status: e.status });
21
+ }
22
+ // or handle other isometric errors
23
+ else {
24
+ return NextResponse.json({
25
+ error: e instanceof funnel_core_1.IsometricError
26
+ ? e.serialize()
27
+ : new funnel_core_1.ServerError().serialize()
28
+ }, { status: 500 });
29
+ }
30
+ }
31
+ }
32
+ FormApi.process = process;
33
+ })(FormApi || (exports.FormApi = FormApi = {}));
34
+ //# sourceMappingURL=FormApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormApi.js","sourceRoot":"","sources":["../../src/forms/FormApi.ts"],"names":[],"mappings":";;;AAAA,6DAAiF;AAIjF,YAAY;AACZ,IAAiB,OAAO,CAgCvB;AAhCD,WAAiB,OAAO;IAEtB,UAAU;IACH,KAAK,UAAU,OAAO,CAAC,OAAoB,EAAE,YAAqC;QAEvF,iBAAiB;QACjB,IAAI,CAAC;YAEH,kBAAkB;YAClB,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAA;QACtD,CAAC;QAED,6BAA6B;QAC7B,OAAO,CAAC,EAAE,CAAC;YAET,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,CAAC,CAAC,CAAA;YAE7D,mBAAmB;YACnB,IAAI,CAAC,YAAY,sBAAQ,EAAE,CAAC;gBAC1B,OAAO,YAAY,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,CAAC,CAAC,SAAS,EAAE,EAAC,EAAE,EAAC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAC,CAAC,CAAA;YACtE,CAAC;YAED,mCAAmC;iBAC9B,CAAC;gBACJ,OAAO,YAAY,CAAC,IAAI,CAAC;oBACvB,KAAK,EAAE,CAAC,YAAY,4BAAc;wBAChC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE;wBACf,CAAC,CAAC,IAAI,yBAAW,EAAE,CAAC,SAAS,EAAE;iBAClC,EAAE,EAAC,MAAM,EAAE,GAAG,EAAC,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IA5BqB,eAAO,UA4B5B,CAAA;AACH,CAAC,EAhCgB,OAAO,uBAAP,OAAO,QAgCvB"}
@@ -0,0 +1 @@
1
+ export * from './FormApi';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./FormApi"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/forms/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB"}
@@ -0,0 +1,12 @@
1
+ export * from './content';
2
+ export * from './forms';
3
+ export * from './middleware';
4
+ export * from './query';
5
+ export * from './LeadGen';
6
+ export * from './RegionalSite';
7
+ export * from './Site';
8
+ export * from './SiteAuth';
9
+ export * from './SiteContent';
10
+ export * from './SiteEngine';
11
+ export * from './SiteLayout';
12
+ export * from './Sitemap';
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./content"), exports);
18
+ __exportStar(require("./forms"), exports);
19
+ __exportStar(require("./middleware"), exports);
20
+ __exportStar(require("./query"), exports);
21
+ __exportStar(require("./LeadGen"), exports);
22
+ __exportStar(require("./RegionalSite"), exports);
23
+ __exportStar(require("./Site"), exports);
24
+ __exportStar(require("./SiteAuth"), exports);
25
+ __exportStar(require("./SiteContent"), exports);
26
+ __exportStar(require("./SiteEngine"), exports);
27
+ __exportStar(require("./SiteLayout"), exports);
28
+ __exportStar(require("./Sitemap"), exports);
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,0CAAuB;AACvB,+CAA4B;AAC5B,0CAAuB;AACvB,4CAAyB;AACzB,iDAA8B;AAC9B,yCAAsB;AACtB,6CAA0B;AAC1B,gDAA6B;AAC7B,+CAA4B;AAC5B,+CAA4B;AAC5B,4CAAyB"}
@@ -0,0 +1,4 @@
1
+ export declare namespace MiddlewarePriority {
2
+ const AUTH = 2;
3
+ const REGIONALIZATION = 5;
4
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MiddlewarePriority = void 0;
4
+ var MiddlewarePriority;
5
+ (function (MiddlewarePriority) {
6
+ MiddlewarePriority.AUTH = 2;
7
+ MiddlewarePriority.REGIONALIZATION = 5;
8
+ })(MiddlewarePriority || (exports.MiddlewarePriority = MiddlewarePriority = {}));
9
+ //# sourceMappingURL=MiddlewarePriority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MiddlewarePriority.js","sourceRoot":"","sources":["../../src/middleware/MiddlewarePriority.ts"],"names":[],"mappings":";;;AAAA,IAAiB,kBAAkB,CAKlC;AALD,WAAiB,kBAAkB;IAEpB,uBAAI,GAAG,CAAC,CAAA;IACR,kCAAe,GAAG,CAAC,CAAA;AAElC,CAAC,EALgB,kBAAkB,kCAAlB,kBAAkB,QAKlC"}
@@ -0,0 +1,12 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { SiteResponse } from './SiteResponse';
3
+ export declare abstract class SiteMiddleware {
4
+ readonly priority: number;
5
+ protected constructor(args: SiteMiddleware.ConstructorArgs);
6
+ abstract execute(request: NextRequest, response: SiteResponse): void;
7
+ }
8
+ export declare namespace SiteMiddleware {
9
+ type ConstructorArgs = {
10
+ priority: number;
11
+ };
12
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SiteMiddleware = void 0;
4
+ // class
5
+ class SiteMiddleware {
6
+ constructor(args) {
7
+ this.priority = args.priority;
8
+ }
9
+ }
10
+ exports.SiteMiddleware = SiteMiddleware;
11
+ //# sourceMappingURL=SiteMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SiteMiddleware.js","sourceRoot":"","sources":["../../src/middleware/SiteMiddleware.ts"],"names":[],"mappings":";;;AAIA,QAAQ;AACR,MAAsB,cAAc;IAKlC,YAAsB,IAAoC;QACxD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;IAC/B,CAAC;CAGF;AAVD,wCAUC"}
@@ -0,0 +1,23 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+ export declare class SiteResponse {
3
+ private static _nextResponse;
4
+ static get nextResponse(): typeof NextResponse;
5
+ static set nextResponse(nextResponse: typeof NextResponse);
6
+ private readonly _initialUrl;
7
+ private readonly _cookies;
8
+ private _route;
9
+ private _finalized;
10
+ constructor(nextRequest: NextRequest);
11
+ setCookie(name: string, value: string, expires?: number): void;
12
+ clearCookie(name: string): void;
13
+ get action(): SiteResponse.Action;
14
+ get path(): string;
15
+ continue(): void;
16
+ redirect(path: string): void;
17
+ rewrite(path: string): void;
18
+ finalize(): NextResponse | null;
19
+ private ensureNotFinalized;
20
+ }
21
+ export declare namespace SiteResponse {
22
+ type Action = 'none' | 'continue' | 'redirect' | 'rewrite';
23
+ }
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SiteResponse = void 0;
4
+ const funnel_core_1 = require("@nascentdigital/funnel-core");
5
+ // class
6
+ class SiteResponse {
7
+ static get nextResponse() {
8
+ // throw if response isn't bound
9
+ const { _nextResponse } = this;
10
+ if (!_nextResponse) {
11
+ throw new funnel_core_1.InvalidOperationError('Attempt to access NextResponse before it\'s bound');
12
+ }
13
+ // return response
14
+ return _nextResponse;
15
+ }
16
+ static set nextResponse(nextResponse) {
17
+ this._nextResponse = nextResponse;
18
+ }
19
+ constructor(nextRequest) {
20
+ // initialize instance variables
21
+ this._initialUrl = nextRequest.nextUrl.clone();
22
+ this._cookies = new Map();
23
+ this._route = { action: 'none', path: nextRequest.nextUrl.pathname };
24
+ this._finalized = false;
25
+ }
26
+ setCookie(name, value, expires) {
27
+ // guard
28
+ this.ensureNotFinalized();
29
+ // update cookie
30
+ this._cookies.set(name, { _type: 'set', value, expires });
31
+ }
32
+ clearCookie(name) {
33
+ // guard
34
+ this.ensureNotFinalized();
35
+ // update cookie
36
+ this._cookies.set(name, { _type: 'clear' });
37
+ }
38
+ get action() {
39
+ return this._route.action;
40
+ }
41
+ get path() {
42
+ return this._route.path;
43
+ }
44
+ continue() {
45
+ // guard
46
+ this.ensureNotFinalized();
47
+ // fail if there's a conflicting operation
48
+ const { _route } = this;
49
+ if (_route.action !== 'none' && _route.action !== 'continue') {
50
+ throw new funnel_core_1.InvalidOperationError(`Cannot continue routing after "${_route.action}"`);
51
+ }
52
+ // update route
53
+ this._route = { action: 'continue', path: _route.path };
54
+ }
55
+ redirect(path) {
56
+ // guard
57
+ this.ensureNotFinalized();
58
+ // fail if there's a conflicting operation
59
+ const { _route } = this;
60
+ if (_route.action !== 'none' && _route.action !== 'redirect') {
61
+ throw new funnel_core_1.InvalidOperationError(`Attempt to change "redirect" action to "${_route.action}"`);
62
+ }
63
+ // update route
64
+ this._route = { action: 'redirect', path };
65
+ }
66
+ rewrite(path) {
67
+ // guard
68
+ this.ensureNotFinalized();
69
+ // fail if there's a conflicting operation
70
+ const { _route } = this;
71
+ if (_route.action !== 'none' && _route.action !== 'rewrite') {
72
+ throw new funnel_core_1.InvalidOperationError(`Attempt to change "rewrite" action to "${_route.action}"`);
73
+ }
74
+ // update route
75
+ this._route = { action: 'rewrite', path };
76
+ }
77
+ finalize() {
78
+ // guard
79
+ this.ensureNotFinalized();
80
+ // mark finalized
81
+ this._finalized = true;
82
+ // bail if no routing or cookies to consider
83
+ const { _initialUrl, _route, _cookies } = this;
84
+ const hasCookies = _cookies.size > 0;
85
+ if (_route.action === 'none' && !hasCookies) {
86
+ return null;
87
+ }
88
+ // create response
89
+ let response;
90
+ switch (_route.action) {
91
+ case 'redirect': {
92
+ const url = _initialUrl.clone();
93
+ url.pathname = _route.path;
94
+ response = SiteResponse.nextResponse.redirect(url);
95
+ break;
96
+ }
97
+ case 'rewrite': {
98
+ const url = _initialUrl.clone();
99
+ url.pathname = _route.path;
100
+ response = SiteResponse.nextResponse.rewrite(url);
101
+ break;
102
+ }
103
+ default: {
104
+ response = SiteResponse.nextResponse.next();
105
+ break;
106
+ }
107
+ }
108
+ // set cookies (if any)
109
+ if (hasCookies) {
110
+ const responseCookies = response.cookies;
111
+ for (const [cookie, action] of _cookies.entries()) {
112
+ // set cookie
113
+ if (action._type === 'set') {
114
+ const { value, expires } = action;
115
+ responseCookies.set(cookie, value, { expires });
116
+ }
117
+ // or clear it
118
+ else {
119
+ responseCookies.delete(cookie);
120
+ }
121
+ }
122
+ }
123
+ // return response
124
+ return response;
125
+ }
126
+ ensureNotFinalized() {
127
+ if (this._finalized) {
128
+ throw new funnel_core_1.InvalidOperationError('Cannot interact with SiteResponse after finalize() invocation');
129
+ }
130
+ }
131
+ }
132
+ exports.SiteResponse = SiteResponse;
133
+ //# sourceMappingURL=SiteResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SiteResponse.js","sourceRoot":"","sources":["../../src/middleware/SiteResponse.ts"],"names":[],"mappings":";;;AAAA,6DAAiE;AAIjE,QAAQ;AACR,MAAa,YAAY;IAIhB,MAAM,KAAK,YAAY;QAE5B,gCAAgC;QAChC,MAAM,EAAC,aAAa,EAAC,GAAG,IAAI,CAAA;QAC5B,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,mCAAqB,CAAC,mDAAmD,CAAC,CAAA;QACtF,CAAC;QAED,kBAAkB;QAClB,OAAO,aAAa,CAAA;IACtB,CAAC;IAEM,MAAM,KAAK,YAAY,CAAC,YAAiC;QAC9D,IAAI,CAAC,aAAa,GAAG,YAAY,CAAA;IACnC,CAAC;IASD,YAAmB,WA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BAC/C,CAAC;gBAED,cAAc;qBACT,CAAC;oBACJ,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;gBAChC,CAAC;YACH,CAAC;QACH,CAAC;QAED,kBAAkB;QAClB,OAAO,QAAQ,CAAA;IACjB,CAAC;IAEO,kBAAkB;QACxB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,IAAI,mCAAqB,CAAC,+DAA+D,CAAC,CAAA;QAClG,CAAC;IACH,CAAC;CACF;AA1KD,oCA0KC"}
@@ -0,0 +1,4 @@
1
+ export * from './regionalization';
2
+ export * from './MiddlewarePriority';
3
+ export * from './SiteMiddleware';
4
+ export * from './SiteResponse';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./regionalization"), exports);
18
+ __exportStar(require("./MiddlewarePriority"), exports);
19
+ __exportStar(require("./SiteMiddleware"), exports);
20
+ __exportStar(require("./SiteResponse"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,uDAAoC;AACpC,mDAAgC;AAChC,iDAA8B"}
@@ -0,0 +1,22 @@
1
+ import { Locale, RegionsConfig } from '@nascentdigital/funnel-core';
2
+ import { RequestCookies } from 'next/dist/compiled/@edge-runtime/cookies';
3
+ import { ReadonlyRequestCookies } from 'next/dist/server/web/spec-extension/adapters/request-cookies';
4
+ import { NextRequest } from 'next/server';
5
+ import { SiteMiddleware } from '../SiteMiddleware';
6
+ import { SiteResponse } from '../SiteResponse';
7
+ export declare class RegionalizationMiddleware<TRegion extends string = string> extends SiteMiddleware {
8
+ protected readonly regionalization: RegionsConfig;
9
+ protected readonly regions: Set<TRegion>;
10
+ protected readonly defaultLocale: Locale<TRegion>;
11
+ constructor(args: RegionalizationMiddleware.ConstructorArgs<TRegion>);
12
+ execute(request: NextRequest, response: SiteResponse): void;
13
+ protected isLocaleValid(locale: Locale<TRegion> | undefined): boolean;
14
+ private inferLocale;
15
+ }
16
+ export declare namespace RegionalizationMiddleware {
17
+ const cookieName = "funnel.locale";
18
+ type ConstructorArgs<TRegion extends string> = Omit<SiteMiddleware.ConstructorArgs, 'priority'> & {
19
+ regionalization: RegionsConfig<TRegion>;
20
+ };
21
+ function findLocale<TRegion extends string>(cookies: RequestCookies | ReadonlyRequestCookies): Locale<TRegion> | undefined;
22
+ }