@adobe/helix-html-pipeline 4.0.3 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [4.1.1](https://github.com/adobe/helix-html-pipeline/compare/v4.1.0...v4.1.1) (2023-07-27)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update dependency @adobe/helix-markdown-support to v6.3.0 ([6c40c95](https://github.com/adobe/helix-html-pipeline/commit/6c40c95c067eb40d51dfe14abdacbc3283f4f789))
7
+
8
+ # [4.1.0](https://github.com/adobe/helix-html-pipeline/compare/v4.0.3...v4.1.0) (2023-07-25)
9
+
10
+
11
+ ### Features
12
+
13
+ * also rewrite custom preview and live host links ([#367](https://github.com/adobe/helix-html-pipeline/issues/367)) ([136376c](https://github.com/adobe/helix-html-pipeline/commit/136376ca41a38c660d4136d969a0e68e1c680edf)), closes [#359](https://github.com/adobe/helix-html-pipeline/issues/359)
14
+
1
15
  ## [4.0.3](https://github.com/adobe/helix-html-pipeline/compare/v4.0.2...v4.0.3) (2023-07-22)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "4.0.3",
3
+ "version": "4.1.1",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  "node": ">=16.x"
40
40
  },
41
41
  "dependencies": {
42
- "@adobe/helix-markdown-support": "6.2.1",
42
+ "@adobe/helix-markdown-support": "6.3.0",
43
43
  "@adobe/helix-shared-utils": "3.0.0",
44
44
  "@adobe/mdast-util-gridtables": "2.0.2",
45
45
  "@adobe/remark-gridtables": "1.0.4",
@@ -77,7 +77,7 @@
77
77
  "eslint-import-resolver-exports": "1.0.0-beta.5",
78
78
  "eslint-plugin-header": "3.1.1",
79
79
  "eslint-plugin-import": "2.27.5",
80
- "esmock": "2.3.1",
80
+ "esmock": "2.3.2",
81
81
  "husky": "8.0.3",
82
82
  "js-yaml": "4.1.0",
83
83
  "jsdom": "22.1.0",
@@ -12,6 +12,7 @@
12
12
  import {PathInfo, S3Loader, FormsMessageDispatcher, PipelineTimer, AuthEnvLoader } from "./index";
13
13
  import {PipelineContent} from "./PipelineContent";
14
14
  import {Modifiers} from './utils/modifiers';
15
+ import {ProjectConfig} from "./project-config";
15
16
 
16
17
  declare enum PipelineType {
17
18
  html = 'html',
@@ -31,13 +32,6 @@ declare interface AccessConfig {
31
32
  };
32
33
  }
33
34
 
34
- declare interface HelixConfigAll {
35
- host:string;
36
- routes:RegExp[];
37
- access?:AccessConfig;
38
- [string]:any;
39
- }
40
-
41
35
  declare interface PipelineOptions {
42
36
  log: Console;
43
37
  s3Loader: S3Loader;
@@ -101,7 +95,7 @@ declare class PipelineState {
101
95
  /**
102
96
  * the /.helix/config.json in object form
103
97
  */
104
- config?: HelixConfigAll;
98
+ config?: ProjectConfig;
105
99
 
106
100
  /**
107
101
  * the metadata.json in modifier form.
@@ -127,5 +121,17 @@ declare class PipelineState {
127
121
  * Authentication information
128
122
  */
129
123
  authInfo?: AuthInfo;
124
+
125
+ /**
126
+ * the custom preview host if configured via config.cdn.preview.host
127
+ * this is initialized after the config is loaded.
128
+ */
129
+ previewHost?: string;
130
+
131
+ /**
132
+ * the custom live host if configured via config.cdn.live.host
133
+ * this is initialized after the config is loaded.
134
+ */
135
+ liveHost?: string;
130
136
  }
131
137
 
@@ -0,0 +1,157 @@
1
+ /*
2
+ * Copyright 2023 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ // NOTE: this file is autogenerated via 'npm run docs:types' in helix-admin-support
14
+
15
+ export interface ProjectConfig {
16
+ /**
17
+ * Name of the project used by the slack bot when reporting.
18
+ */
19
+ name?: string;
20
+ /**
21
+ * Name of the project used by the sidekick.
22
+ */
23
+ project?: string;
24
+ /**
25
+ * Timezone to be used by the slack bot when reporting times.
26
+ */
27
+ timezone?: string;
28
+ /**
29
+ * Production host use by the slack bot to display project information.
30
+ */
31
+ host?: string;
32
+ /**
33
+ * configuration blueprint repository in the owner/repo format.
34
+ */
35
+ blueprint?: string;
36
+ /**
37
+ * the slack teamId/channelID(s) where the slack bot is used.
38
+ */
39
+ slack?: string | string[];
40
+ cdn?: ProjectCDNConfig;
41
+ access?: SiteAccessConfig;
42
+ admin?: AdminConfig;
43
+ }
44
+ /**
45
+ * The CDN config
46
+ */
47
+ export interface ProjectCDNConfig {
48
+ prod: FastlyConfig | AkamaiConfig | CloudflareConfig | ManagedConfig;
49
+ live?: {
50
+ /**
51
+ * Sidekick config to override the default preview host. it supports parameters $owner and $repo
52
+ */
53
+ host: string;
54
+ };
55
+ preview?: {
56
+ /**
57
+ * Sidekick config to override the default live host. it supports parameters $owner and $repo
58
+ */
59
+ host: string;
60
+ };
61
+ }
62
+ /**
63
+ * Production CDN configuration for Fastly
64
+ */
65
+ export interface FastlyConfig {
66
+ type: 'fastly';
67
+ /**
68
+ * production host
69
+ */
70
+ host: string;
71
+ /**
72
+ * Route or routes on the CDN that are rendered with Franklin
73
+ */
74
+ route: string | string[];
75
+ /**
76
+ * The Fastly Service ID
77
+ */
78
+ serviceId: string;
79
+ /**
80
+ * A Fastly token for purging
81
+ */
82
+ authToken: string;
83
+ }
84
+ export interface AkamaiConfig {
85
+ type: 'akamai';
86
+ /**
87
+ * production host
88
+ */
89
+ host: string;
90
+ /**
91
+ * Route or routes on the CDN that are rendered with Franklin
92
+ */
93
+ route: string | string[];
94
+ endpoint: string;
95
+ clientSecret: string;
96
+ clientToken: string;
97
+ accessToken: string;
98
+ }
99
+ export interface CloudflareConfig {
100
+ type: 'cloudflare';
101
+ /**
102
+ * production host
103
+ */
104
+ host: string;
105
+ /**
106
+ * Route or routes on the CDN that are rendered with Franklin
107
+ */
108
+ route: string | string[];
109
+ origin: string;
110
+ plan: string;
111
+ zoneId: string;
112
+ apiToken: string;
113
+ }
114
+ export interface ManagedConfig {
115
+ type: 'managed';
116
+ /**
117
+ * production host
118
+ */
119
+ host: string;
120
+ /**
121
+ * Route or routes on the CDN that are rendered with Franklin
122
+ */
123
+ route: string | string[];
124
+ }
125
+ export interface SiteAccessConfig {
126
+ /**
127
+ * The email glob of the users that are allowed.
128
+ */
129
+ allow: string | string[];
130
+ /**
131
+ * the id of the API key(s). this is used to validate the API KEYS and allows to invalidate them.
132
+ */
133
+ apiKeyId?: string | string[];
134
+ require?: {
135
+ /**
136
+ * The list of owner/repo pointers to projects that are allowed to use this content.
137
+ */
138
+ repository: string | string[];
139
+ };
140
+ }
141
+ export interface AdminConfig {
142
+ role?: Role;
143
+ /**
144
+ * the id of the API key(s). this is used to validate the API KEYS and allows to invalidate them.
145
+ */
146
+ apiKeyId?: string | string[];
147
+ }
148
+ export interface Role {
149
+ /**
150
+ * The email glob of the users with author role.
151
+ */
152
+ author?: string | string[];
153
+ /**
154
+ * The email glob of the users with publish role.
155
+ */
156
+ publish?: string | string[];
157
+ }
@@ -87,6 +87,15 @@ export function computeRoutes(value) {
87
87
  });
88
88
  }
89
89
 
90
+ function replaceParams(str, info) {
91
+ if (!str) {
92
+ return '';
93
+ }
94
+ return str
95
+ .replaceAll('$owner', info.owner)
96
+ .replaceAll('$repo', info.repo);
97
+ }
98
+
90
99
  /**
91
100
  * Loads the /.helix/config-all.json from the content-bus and stores it in the state. if no
92
101
  * such config exists, it will load the metadata.json as fallback and separate out the
@@ -117,6 +126,9 @@ export default async function fetchConfigAll(state, req, res) {
117
126
  // also update last-modified (only for extensionless html pipeline)
118
127
  updateLastModified(state, res, extractLastModified(ret.headers));
119
128
  }
129
+ // set custom preview and live hosts
130
+ state.previewHost = replaceParams(state.config.cdn?.preview?.host, state);
131
+ state.liveHost = replaceParams(state.config.cdn?.live?.host, state);
120
132
  } else if (ret.status !== 404) {
121
133
  throw new PipelineStatusError(502, `failed to load /.helix/config-all.json: ${ret.status}`);
122
134
  } else {
@@ -186,7 +186,9 @@ export function rewriteUrl(state, url) {
186
186
  return url;
187
187
  }
188
188
  try {
189
- const { pathname, search, hash } = new URL(url);
189
+ const {
190
+ host, pathname, search, hash,
191
+ } = new URL(url);
190
192
 
191
193
  if (AZURE_BLOB_REGEXP.test(url)) {
192
194
  const filename = pathname.split('/').pop();
@@ -200,7 +202,9 @@ export function rewriteUrl(state, url) {
200
202
  return `.${pathname}${hash}`;
201
203
  }
202
204
 
203
- if (HELIX_URL_REGEXP.test(url)) {
205
+ if (HELIX_URL_REGEXP.test(url)
206
+ || host === state.previewHost
207
+ || host === state.liveHost) {
204
208
  if (hash && pathname === state.info?.path) {
205
209
  return hash;
206
210
  }