@fastly/compute-js-static-publish 6.3.0 → 7.0.0-beta.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.
Files changed (238) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +31 -586
  3. package/README.short.md +53 -0
  4. package/build/cli/commands/clean.d.ts +2 -0
  5. package/build/cli/commands/clean.d.ts.map +1 -0
  6. package/build/cli/commands/clean.js +121 -0
  7. package/build/cli/commands/collections/delete.d.ts +2 -0
  8. package/build/cli/commands/collections/delete.d.ts.map +1 -0
  9. package/build/cli/commands/collections/delete.js +88 -0
  10. package/build/cli/commands/collections/index.d.ts +2 -0
  11. package/build/cli/commands/collections/index.d.ts.map +1 -0
  12. package/build/cli/commands/collections/index.js +52 -0
  13. package/build/cli/commands/collections/list.d.ts +2 -0
  14. package/build/cli/commands/collections/list.d.ts.map +1 -0
  15. package/build/cli/commands/collections/list.js +62 -0
  16. package/build/cli/commands/index.d.ts +2 -0
  17. package/build/cli/commands/index.d.ts.map +1 -0
  18. package/build/cli/commands/index.js +67 -0
  19. package/build/cli/commands/init-app.d.ts +18 -2
  20. package/build/cli/commands/init-app.d.ts.map +1 -1
  21. package/build/cli/commands/init-app.js +291 -264
  22. package/build/cli/commands/publish-content.d.ts +2 -0
  23. package/build/cli/commands/publish-content.d.ts.map +1 -0
  24. package/build/cli/commands/publish-content.js +472 -0
  25. package/build/cli/compression/brotli.d.ts +1 -1
  26. package/build/cli/compression/brotli.d.ts.map +1 -1
  27. package/build/cli/compression/brotli.js +8 -11
  28. package/build/cli/compression/gzip.d.ts +1 -1
  29. package/build/cli/compression/gzip.d.ts.map +1 -1
  30. package/build/cli/compression/gzip.js +8 -11
  31. package/build/cli/compression/index.d.ts +3 -6
  32. package/build/cli/compression/index.d.ts.map +1 -1
  33. package/build/cli/compression/index.js +8 -9
  34. package/build/cli/fastly-api/api-token.d.ts +17 -0
  35. package/build/cli/fastly-api/api-token.d.ts.map +1 -0
  36. package/build/cli/fastly-api/api-token.js +94 -0
  37. package/build/cli/fastly-api/kv-store.d.ts +24 -0
  38. package/build/cli/fastly-api/kv-store.d.ts.map +1 -0
  39. package/build/cli/{util → fastly-api}/kv-store.js +42 -22
  40. package/build/cli/index.js +7 -91
  41. package/build/cli/util/args.d.ts +16 -0
  42. package/build/cli/util/args.d.ts.map +1 -0
  43. package/build/cli/util/args.js +55 -0
  44. package/build/cli/util/config.d.ts +13 -0
  45. package/build/cli/util/config.d.ts.map +1 -0
  46. package/build/cli/{load-config.js → util/config.js} +234 -187
  47. package/build/{util → cli/util}/content-types.d.ts +1 -2
  48. package/build/cli/util/content-types.d.ts.map +1 -0
  49. package/build/{util → cli/util}/content-types.js +11 -6
  50. package/build/cli/util/data.d.ts +3 -3
  51. package/build/cli/util/data.d.ts.map +1 -1
  52. package/build/cli/util/data.js +6 -2
  53. package/build/cli/util/files.d.ts +10 -2
  54. package/build/cli/util/files.d.ts.map +1 -1
  55. package/build/cli/util/files.js +53 -6
  56. package/build/cli/util/kv-store-items.d.ts +12 -0
  57. package/build/cli/util/kv-store-items.d.ts.map +1 -0
  58. package/build/cli/util/kv-store-items.js +161 -0
  59. package/build/cli/util/kv-store-local-server.d.ts +3 -0
  60. package/build/cli/util/kv-store-local-server.d.ts.map +1 -0
  61. package/build/cli/util/kv-store-local-server.js +35 -0
  62. package/build/cli/util/package.d.ts +9 -0
  63. package/build/cli/util/package.d.ts.map +1 -0
  64. package/build/cli/util/package.js +44 -0
  65. package/build/cli/util/retryable.d.ts +12 -0
  66. package/build/cli/util/retryable.d.ts.map +1 -0
  67. package/build/cli/util/retryable.js +43 -0
  68. package/build/cli/util/variants.d.ts +4 -0
  69. package/build/cli/util/variants.d.ts.map +1 -0
  70. package/build/cli/util/variants.js +27 -0
  71. package/build/index.d.ts +5 -5
  72. package/build/index.d.ts.map +1 -1
  73. package/build/index.js +7 -6
  74. package/build/models/assets/kvstore-assets.d.ts +17 -0
  75. package/build/models/assets/kvstore-assets.d.ts.map +1 -0
  76. package/build/models/assets/kvstore-assets.js +28 -0
  77. package/build/{constants/compression.d.ts → models/compression/index.d.ts} +2 -1
  78. package/build/models/compression/index.d.ts.map +1 -0
  79. package/build/models/compression/index.js +11 -0
  80. package/build/models/config/publish-content-config.d.ts +41 -0
  81. package/build/models/config/publish-content-config.d.ts.map +1 -0
  82. package/build/models/config/publish-content-config.js +5 -0
  83. package/build/models/config/publisher-server-config.d.ts +20 -0
  84. package/build/models/config/publisher-server-config.d.ts.map +1 -0
  85. package/build/models/config/publisher-server-config.js +5 -0
  86. package/build/models/config/static-publish-rc.d.ts +6 -0
  87. package/build/models/config/static-publish-rc.d.ts.map +1 -0
  88. package/build/models/config/static-publish-rc.js +5 -0
  89. package/build/server/collection-selector/from-config-store.d.ts +2 -0
  90. package/build/server/collection-selector/from-config-store.d.ts.map +1 -0
  91. package/build/server/collection-selector/from-config-store.js +15 -0
  92. package/build/server/collection-selector/from-cookie.d.ts +23 -0
  93. package/build/server/collection-selector/from-cookie.d.ts.map +1 -0
  94. package/build/server/collection-selector/from-cookie.js +98 -0
  95. package/build/server/collection-selector/from-request.d.ts +13 -0
  96. package/build/server/collection-selector/from-request.d.ts.map +1 -0
  97. package/build/server/collection-selector/from-request.js +22 -0
  98. package/build/server/collection-selector/index.d.ts +5 -0
  99. package/build/server/collection-selector/index.d.ts.map +1 -0
  100. package/build/server/collection-selector/index.js +7 -0
  101. package/build/server/collection-selector/request-collection-selector.d.ts +5 -0
  102. package/build/server/collection-selector/request-collection-selector.d.ts.map +1 -0
  103. package/build/server/collection-selector/request-collection-selector.js +5 -0
  104. package/build/server/publisher-server/index.d.ts +38 -0
  105. package/build/server/publisher-server/index.d.ts.map +1 -0
  106. package/build/server/publisher-server/index.js +415 -0
  107. package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts +3 -0
  108. package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +1 -0
  109. package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-modified-since.js +6 -2
  110. package/build/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +1 -0
  111. package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-none-match.js +4 -0
  112. package/build/server/util/cookies.d.ts +2 -0
  113. package/build/server/util/cookies.d.ts.map +1 -0
  114. package/build/server/util/cookies.js +14 -0
  115. package/build/server/util/kv-store.d.ts +3 -0
  116. package/build/server/util/kv-store.d.ts.map +1 -0
  117. package/build/server/util/kv-store.js +95 -0
  118. package/package.json +18 -10
  119. package/build/cli/commands/build-static.d.ts +0 -3
  120. package/build/cli/commands/build-static.d.ts.map +0 -1
  121. package/build/cli/commands/build-static.js +0 -541
  122. package/build/cli/commands/clean-kv-store.d.ts +0 -3
  123. package/build/cli/commands/clean-kv-store.d.ts.map +0 -1
  124. package/build/cli/commands/clean-kv-store.js +0 -55
  125. package/build/cli/load-config.d.ts +0 -6
  126. package/build/cli/load-config.d.ts.map +0 -1
  127. package/build/cli/presets/implementations/astro.d.ts +0 -7
  128. package/build/cli/presets/implementations/astro.d.ts.map +0 -1
  129. package/build/cli/presets/implementations/astro.js +0 -23
  130. package/build/cli/presets/implementations/create-react-app.d.ts +0 -11
  131. package/build/cli/presets/implementations/create-react-app.d.ts.map +0 -1
  132. package/build/cli/presets/implementations/create-react-app.js +0 -34
  133. package/build/cli/presets/implementations/docusaurus.d.ts +0 -7
  134. package/build/cli/presets/implementations/docusaurus.d.ts.map +0 -1
  135. package/build/cli/presets/implementations/docusaurus.js +0 -13
  136. package/build/cli/presets/implementations/gatsby.d.ts +0 -7
  137. package/build/cli/presets/implementations/gatsby.d.ts.map +0 -1
  138. package/build/cli/presets/implementations/gatsby.js +0 -13
  139. package/build/cli/presets/implementations/next.d.ts +0 -7
  140. package/build/cli/presets/implementations/next.d.ts.map +0 -1
  141. package/build/cli/presets/implementations/next.js +0 -13
  142. package/build/cli/presets/implementations/sveltekit.d.ts +0 -7
  143. package/build/cli/presets/implementations/sveltekit.d.ts.map +0 -1
  144. package/build/cli/presets/implementations/sveltekit.js +0 -13
  145. package/build/cli/presets/implementations/vite.d.ts +0 -7
  146. package/build/cli/presets/implementations/vite.d.ts.map +0 -1
  147. package/build/cli/presets/implementations/vite.js +0 -13
  148. package/build/cli/presets/implementations/vue.d.ts +0 -7
  149. package/build/cli/presets/implementations/vue.d.ts.map +0 -1
  150. package/build/cli/presets/implementations/vue.js +0 -24
  151. package/build/cli/presets/index.d.ts +0 -3
  152. package/build/cli/presets/index.d.ts.map +0 -1
  153. package/build/cli/presets/index.js +0 -20
  154. package/build/cli/presets/preset-base.d.ts +0 -21
  155. package/build/cli/presets/preset-base.d.ts.map +0 -1
  156. package/build/cli/presets/preset-base.js +0 -1
  157. package/build/cli/util/fastly-api.d.ts +0 -10
  158. package/build/cli/util/fastly-api.d.ts.map +0 -1
  159. package/build/cli/util/fastly-api.js +0 -47
  160. package/build/cli/util/hash.d.ts +0 -5
  161. package/build/cli/util/hash.d.ts.map +0 -1
  162. package/build/cli/util/hash.js +0 -9
  163. package/build/cli/util/id.d.ts +0 -3
  164. package/build/cli/util/id.d.ts.map +0 -1
  165. package/build/cli/util/id.js +0 -17
  166. package/build/cli/util/kv-store.d.ts +0 -16
  167. package/build/cli/util/kv-store.d.ts.map +0 -1
  168. package/build/cli/util/publish-id.d.ts +0 -5
  169. package/build/cli/util/publish-id.d.ts.map +0 -1
  170. package/build/cli/util/publish-id.js +0 -26
  171. package/build/compute-js.d.ts +0 -3
  172. package/build/compute-js.d.ts.map +0 -1
  173. package/build/compute-js.js +0 -2
  174. package/build/constants/compression.d.ts.map +0 -1
  175. package/build/constants/compression.js +0 -4
  176. package/build/server/assets/asset-manager.d.ts +0 -8
  177. package/build/server/assets/asset-manager.d.ts.map +0 -1
  178. package/build/server/assets/asset-manager.js +0 -14
  179. package/build/server/assets/content-asset-kv-store.d.ts +0 -19
  180. package/build/server/assets/content-asset-kv-store.d.ts.map +0 -1
  181. package/build/server/assets/content-asset-kv-store.js +0 -70
  182. package/build/server/assets/content-asset-wasm-inline.d.ts +0 -18
  183. package/build/server/assets/content-asset-wasm-inline.d.ts.map +0 -1
  184. package/build/server/assets/content-asset-wasm-inline.js +0 -52
  185. package/build/server/assets/content-assets.d.ts +0 -46
  186. package/build/server/assets/content-assets.d.ts.map +0 -1
  187. package/build/server/assets/content-assets.js +0 -100
  188. package/build/server/assets/module-assets.d.ts +0 -23
  189. package/build/server/assets/module-assets.d.ts.map +0 -1
  190. package/build/server/assets/module-assets.js +0 -45
  191. package/build/server/kv-store/inline-store-entry.d.ts +0 -25
  192. package/build/server/kv-store/inline-store-entry.d.ts.map +0 -1
  193. package/build/server/kv-store/inline-store-entry.js +0 -100
  194. package/build/server/publisher-server.d.ts +0 -23
  195. package/build/server/publisher-server.d.ts.map +0 -1
  196. package/build/server/publisher-server.js +0 -257
  197. package/build/server/serve-preconditions/if-modified-since.d.ts +0 -4
  198. package/build/server/serve-preconditions/if-modified-since.d.ts.map +0 -1
  199. package/build/server/serve-preconditions/if-none-match.d.ts.map +0 -1
  200. package/build/server/util/http.d.ts +0 -2
  201. package/build/server/util/http.d.ts.map +0 -1
  202. package/build/server/util/http.js +0 -9
  203. package/build/types/compute.d.ts +0 -11
  204. package/build/types/compute.d.ts.map +0 -1
  205. package/build/types/compute.js +0 -1
  206. package/build/types/config-normalized.d.ts +0 -34
  207. package/build/types/config-normalized.d.ts.map +0 -1
  208. package/build/types/config-normalized.js +0 -1
  209. package/build/types/config.d.ts +0 -37
  210. package/build/types/config.d.ts.map +0 -1
  211. package/build/types/config.js +0 -1
  212. package/build/types/content-assets.d.ts +0 -55
  213. package/build/types/content-assets.d.ts.map +0 -1
  214. package/build/types/content-assets.js +0 -1
  215. package/build/types/content-types.d.ts +0 -11
  216. package/build/types/content-types.d.ts.map +0 -1
  217. package/build/types/content-types.js +0 -1
  218. package/build/types/index.d.ts +0 -7
  219. package/build/types/index.d.ts.map +0 -1
  220. package/build/types/index.js +0 -1
  221. package/build/types/module-assets.d.ts +0 -15
  222. package/build/types/module-assets.d.ts.map +0 -1
  223. package/build/types/module-assets.js +0 -1
  224. package/build/types/util.d.ts +0 -7
  225. package/build/types/util.d.ts.map +0 -1
  226. package/build/types/util.js +0 -1
  227. package/build/util/content-types.d.ts.map +0 -1
  228. package/build/util/index.d.ts +0 -3
  229. package/build/util/index.d.ts.map +0 -1
  230. package/build/util/index.js +0 -2
  231. package/build/util/metadata.d.ts +0 -3
  232. package/build/util/metadata.d.ts.map +0 -1
  233. package/build/util/metadata.js +0 -12
  234. package/resources/README.md +0 -3
  235. package/resources/statics-metadata.d.ts +0 -10
  236. package/resources/statics.d.ts +0 -19
  237. package/resources/webpack.config.js +0 -41
  238. /package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-none-match.d.ts +0 -0
@@ -1,179 +1,139 @@
1
- import url from "url";
2
- import path from "path";
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import path from 'node:path';
3
6
  import globToRegExp from 'glob-to-regexp';
4
- import { buildNormalizeFunctionForArray, buildNormalizeFunctionForObject, isSpecified, isStringAndNotEmpty, } from "./util/data.js";
5
- const normalizeContentTypeDef = buildNormalizeFunctionForObject((config, errors) => {
6
- let { test, contentType, text } = config;
7
- if (typeof test === 'function' || test instanceof RegExp) {
8
- // ok
7
+ import { buildNormalizeFunctionForArray, buildNormalizeFunctionForObject, isSpecified, isStringAndNotEmpty, } from './data.js';
8
+ export class LoadConfigError extends Error {
9
+ constructor(configFilePath, errors) {
10
+ super(`Error loading config file ${configFilePath}`);
11
+ this.errors = errors;
9
12
  }
10
- else {
11
- errors.push('test cannot be null.');
13
+ }
14
+ export async function loadStaticPublisherRcFile() {
15
+ let configRaw;
16
+ const configFile = './static-publish.rc.js';
17
+ try {
18
+ const filePath = path.resolve(configFile);
19
+ configRaw = (await import(filePath)).default;
12
20
  }
13
- if (isStringAndNotEmpty(contentType)) {
14
- // ok
21
+ catch {
22
+ //
15
23
  }
16
- else {
17
- errors.push('contentType must be a non-empty string.');
24
+ if (configRaw == null) {
25
+ throw new LoadConfigError(configFile, [
26
+ 'Unable to load ' + configFile,
27
+ ]);
18
28
  }
19
- if (!isSpecified(config, 'text')) {
20
- text = true;
29
+ const errors = [];
30
+ const config = normalizeStaticPublisherRc(configRaw, errors);
31
+ if (config == null) {
32
+ throw new LoadConfigError(configFile, errors);
33
+ }
34
+ return config;
35
+ }
36
+ export const normalizeStaticPublisherRc = buildNormalizeFunctionForObject((config, errors) => {
37
+ let { kvStoreName, publishId, defaultCollectionName, } = config;
38
+ if (!isSpecified(config, 'kvStoreName')) {
39
+ errors.push('kvStoreName must be specified.');
21
40
  }
22
41
  else {
23
- if (typeof text === 'boolean') {
42
+ if (isStringAndNotEmpty(kvStoreName)) {
24
43
  // ok
25
44
  }
26
45
  else {
27
- errors.push('text, if specified, must be a boolean value.');
46
+ errors.push('kvStoreName must be a non-empty string.');
28
47
  }
29
48
  }
30
- if (errors.length > 0) {
31
- return null;
32
- }
33
- return {
34
- test,
35
- contentType,
36
- text,
37
- };
38
- });
39
- const normalizeContentTypeDefs = buildNormalizeFunctionForArray((config, errors) => {
40
- return normalizeContentTypeDef(config, errors);
41
- });
42
- const normalizePublisherServerConfig = buildNormalizeFunctionForObject((config, errors) => {
43
- let { publicDirPrefix, staticItems, compression, spaFile, notFoundPageFile, autoExt, autoIndex } = config;
44
- if (!isSpecified(config, 'publicDirPrefix')) {
45
- publicDirPrefix = '';
49
+ if (!isSpecified(config, 'publishId')) {
50
+ errors.push('publishId must be specified.');
46
51
  }
47
52
  else {
48
- if (typeof publicDirPrefix === 'string') {
53
+ if (isStringAndNotEmpty(publishId)) {
49
54
  // ok
50
55
  }
51
56
  else {
52
- errors.push('publicDirPrefix, if specified, must be a string value.');
57
+ errors.push('publishId must be a non-empty string.');
53
58
  }
54
59
  }
55
- if (!isSpecified(config, 'staticItems')) {
56
- staticItems = [];
60
+ if (!isSpecified(config, 'defaultCollectionName')) {
61
+ errors.push('defaultCollectionName must be specified.');
57
62
  }
58
63
  else {
59
- if (staticItems === null || staticItems === false) {
60
- staticItems = [];
61
- }
62
- if (!Array.isArray(staticItems)) {
63
- staticItems = [staticItems];
64
- }
65
- if (staticItems.every((x) => typeof x === 'string')) {
66
- staticItems = staticItems.map((x, index) => {
67
- if (x.includes('*')) {
68
- let re;
69
- try {
70
- const regexp = globToRegExp(x, { globstar: true });
71
- re = 're:' + String(regexp);
72
- }
73
- catch {
74
- errors.push(`staticItems item at index ${index}, '${x}', cannot be parsed as glob pattern.`);
75
- re = null;
76
- }
77
- return re;
78
- }
79
- return x;
80
- });
64
+ if (isStringAndNotEmpty(defaultCollectionName)) {
65
+ // ok
81
66
  }
82
67
  else {
83
- errors.push('staticItems, if specified, must be a string value, an array of string values, false, or null');
68
+ errors.push('defaultCollectionName must be a non-empty string.');
84
69
  }
85
70
  }
86
- if (!isSpecified(config, 'compression')) {
87
- compression = ['br', 'gzip'];
71
+ return {
72
+ kvStoreName,
73
+ publishId,
74
+ defaultCollectionName,
75
+ };
76
+ });
77
+ export async function loadPublishContentConfigFile(configFile) {
78
+ let configRaw;
79
+ try {
80
+ const filePath = path.resolve(configFile);
81
+ configRaw = (await import(filePath)).default;
88
82
  }
89
- else if (compression === null) {
90
- compression = [];
83
+ catch {
84
+ //
91
85
  }
92
- else {
93
- if (!Array.isArray(compression)) {
94
- compression = [compression];
95
- }
96
- if (compression.some((x) => x !== 'br' && x !== 'gzip')) {
97
- errors.push(`compression, if specified, must be null or an array and can only contain 'br' and 'gzip'.`);
98
- }
86
+ if (configRaw == null) {
87
+ throw new LoadConfigError(configFile, [
88
+ 'Unable to load ' + configFile,
89
+ ]);
99
90
  }
100
- if (!isSpecified(config, 'spaFile')) {
101
- spaFile = null;
102
- }
103
- else {
104
- if (typeof spaFile === 'string' || spaFile === null) {
105
- // ok
106
- }
107
- else if (spaFile === false) {
108
- spaFile = null;
109
- }
110
- else {
111
- errors.push('spaFile, if specified, must be a string value, false, or null');
112
- }
91
+ const errors = [];
92
+ const config = normalizePublishContentConfig(configRaw, errors);
93
+ if (config == null) {
94
+ throw new LoadConfigError(configFile, errors);
113
95
  }
114
- if (!isSpecified(config, 'notFoundPageFile')) {
115
- notFoundPageFile = null;
96
+ return config;
97
+ }
98
+ const normalizeContentTypeDef = buildNormalizeFunctionForObject((config, errors) => {
99
+ let { test, contentType, text } = config;
100
+ if (typeof test === 'function' || test instanceof RegExp) {
101
+ // ok
116
102
  }
117
103
  else {
118
- if (typeof notFoundPageFile === 'string' || notFoundPageFile === null) {
119
- // ok
120
- }
121
- else if (notFoundPageFile === false) {
122
- notFoundPageFile = null;
123
- }
124
- else {
125
- errors.push('notFoundPageFile, if specified, must be a string value, false, or null');
126
- }
104
+ errors.push('test cannot be null.');
127
105
  }
128
- if (!isSpecified(config, 'autoExt')) {
129
- autoExt = [];
106
+ if (isStringAndNotEmpty(contentType)) {
107
+ // ok
130
108
  }
131
109
  else {
132
- if (Array.isArray(autoExt) && autoExt.every(e => typeof e === 'string')) {
133
- // ok
134
- }
135
- else if (autoExt === false || autoExt === null) {
136
- autoExt = [];
137
- }
138
- else if (typeof autoExt === 'string') {
139
- autoExt = [autoExt];
140
- }
141
- else {
142
- errors.push('autoExt, if specified, must be an array of string values, a string value, false, or null');
143
- }
110
+ errors.push('contentType must be a non-empty string.');
144
111
  }
145
- if (!isSpecified(config, 'autoIndex')) {
146
- autoIndex = [];
112
+ if (!isSpecified(config, 'text')) {
113
+ text = true;
147
114
  }
148
115
  else {
149
- if (Array.isArray(autoIndex) && autoIndex.every(e => typeof e === 'string')) {
116
+ if (typeof text === 'boolean') {
150
117
  // ok
151
118
  }
152
- else if (autoIndex === false || autoIndex === null) {
153
- autoIndex = [];
154
- }
155
- else if (typeof autoIndex === 'string') {
156
- autoIndex = [autoIndex];
157
- }
158
119
  else {
159
- errors.push('autoIndex, if specified, must be an array of string values, a string value, false, or null');
120
+ errors.push('text, if specified, must be a boolean value.');
160
121
  }
161
122
  }
162
123
  if (errors.length > 0) {
163
124
  return null;
164
125
  }
165
126
  return {
166
- publicDirPrefix,
167
- staticItems,
168
- compression,
169
- spaFile,
170
- notFoundPageFile,
171
- autoExt,
172
- autoIndex,
127
+ test,
128
+ contentType,
129
+ text,
173
130
  };
174
131
  });
175
- const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
176
- let { rootDir, staticContentRootDir, kvStoreName, excludeDirs, excludeDotFiles, includeWellKnown, contentAssetInclusionTest, contentCompression, moduleAssetInclusionTest, contentTypes, server, } = config;
132
+ const normalizeContentTypeDefs = buildNormalizeFunctionForArray((config, errors) => {
133
+ return normalizeContentTypeDef(config, errors);
134
+ });
135
+ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((config, errors) => {
136
+ let { rootDir, staticPublisherWorkingDir, excludeDirs, excludeDotFiles, includeWellKnown, kvStoreAssetInclusionTest, contentCompression, contentTypes, server, } = config;
177
137
  if (!isSpecified(config, 'rootDir')) {
178
138
  errors.push('rootDir must be specified.');
179
139
  }
@@ -185,34 +145,20 @@ const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
185
145
  errors.push('rootDir must be a non-empty string.');
186
146
  }
187
147
  }
188
- if (!isSpecified(config, 'staticContentRootDir')) {
189
- staticContentRootDir = './src';
148
+ if (!isSpecified(config, 'staticPublisherWorkingDir')) {
149
+ errors.push('staticPublisherWorkingDir must be specified.');
190
150
  }
191
151
  else {
192
- if (staticContentRootDir.startsWith('./') &&
193
- staticContentRootDir !== './' &&
194
- !staticContentRootDir.includes('//')) {
152
+ if (staticPublisherWorkingDir.startsWith('./') &&
153
+ staticPublisherWorkingDir !== './' &&
154
+ !staticPublisherWorkingDir.includes('//')) {
195
155
  // ok
196
156
  }
197
157
  else {
198
- errors.push('staticContentRootDir must be a relative subdirectory.');
199
- }
200
- while (staticContentRootDir.endsWith('/')) {
201
- staticContentRootDir = staticContentRootDir.slice(0, -1);
202
- }
203
- }
204
- if (!isSpecified(config, 'kvStoreName')) {
205
- kvStoreName = null;
206
- }
207
- else {
208
- if (isStringAndNotEmpty(kvStoreName) || kvStoreName === null) {
209
- // ok
210
- }
211
- else if (kvStoreName === false) {
212
- kvStoreName = null;
158
+ errors.push('staticPublisherWorkingDir must be a relative subdirectory.');
213
159
  }
214
- else {
215
- errors.push('kvStoreName, if specified, must be a non-empty string, false, or null.');
160
+ while (staticPublisherWorkingDir.endsWith('/')) {
161
+ staticPublisherWorkingDir = staticPublisherWorkingDir.slice(0, -1);
216
162
  }
217
163
  }
218
164
  if (!isSpecified(config, 'excludeDotFiles')) {
@@ -274,22 +220,17 @@ const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
274
220
  if (excludeDirs.some((x) => x == null)) {
275
221
  errors.push('excludeDirs, if specified, must be null, a string value, a RegExp, or an array of strings and RegExp values.');
276
222
  }
277
- if (!isSpecified(config, 'contentAssetInclusionTest')) {
278
- contentAssetInclusionTest = null;
223
+ if (!isSpecified(config, 'kvStoreAssetInclusionTest')) {
224
+ kvStoreAssetInclusionTest = null;
279
225
  }
280
- else if (contentAssetInclusionTest === null || typeof contentAssetInclusionTest === 'function') {
226
+ else if (kvStoreAssetInclusionTest === null || typeof kvStoreAssetInclusionTest === 'function') {
281
227
  // ok
282
228
  }
283
229
  else {
284
- errors.push('contentAssetInclusionTest, if specified, must be null or a function.');
230
+ errors.push('kvStoreAssetInclusionTest, if specified, must be null or a function.');
285
231
  }
286
232
  if (!isSpecified(config, 'contentCompression')) {
287
- if (kvStoreName != null) {
288
- contentCompression = ['br', 'gzip'];
289
- }
290
- else {
291
- contentCompression = [];
292
- }
233
+ contentCompression = ['br', 'gzip'];
293
234
  }
294
235
  else if (contentCompression === null) {
295
236
  contentCompression = [];
@@ -302,15 +243,6 @@ const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
302
243
  errors.push(`contentCompression, if specified, must be null or an array and can only contain 'br' and 'gzip'.`);
303
244
  }
304
245
  }
305
- if (!isSpecified(config, 'moduleAssetInclusionTest')) {
306
- moduleAssetInclusionTest = null;
307
- }
308
- else if (moduleAssetInclusionTest === null || typeof moduleAssetInclusionTest === 'function') {
309
- // ok
310
- }
311
- else {
312
- errors.push('moduleAssetInclusionTest, if specified, must be null or a function.');
313
- }
314
246
  if (!isSpecified(config, 'contentTypes')) {
315
247
  contentTypes = [];
316
248
  }
@@ -352,31 +284,146 @@ const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
352
284
  }
353
285
  return {
354
286
  rootDir,
355
- staticContentRootDir,
356
- kvStoreName,
287
+ staticPublisherWorkingDir,
288
+ excludeDirs,
357
289
  excludeDotFiles,
358
290
  includeWellKnown,
359
- excludeDirs,
360
- contentAssetInclusionTest,
291
+ kvStoreAssetInclusionTest,
361
292
  contentCompression,
362
- moduleAssetInclusionTest,
363
293
  contentTypes,
364
294
  server,
365
295
  };
366
296
  });
367
- export async function loadConfigFile(errors = []) {
368
- let raw = undefined;
369
- const staticPublishRcPath = path.resolve('./static-publish.rc.js');
370
- const staticPublishRcFileURL = String(url.pathToFileURL(staticPublishRcPath));
371
- try {
372
- raw = (await import(staticPublishRcFileURL)).default;
297
+ export const normalizePublisherServerConfig = buildNormalizeFunctionForObject((config, errors) => {
298
+ let { publicDirPrefix, staticItems, allowedEncodings, spaFile, notFoundPageFile, autoExt, autoIndex, } = config;
299
+ if (!isSpecified(config, 'publicDirPrefix')) {
300
+ publicDirPrefix = '';
373
301
  }
374
- catch {
375
- errors.push('Unable to load ' + staticPublishRcFileURL);
302
+ else {
303
+ if (typeof publicDirPrefix === 'string') {
304
+ // ok
305
+ }
306
+ else {
307
+ errors.push('publicDirPrefix, if specified, must be a string value.');
308
+ }
376
309
  }
377
- let normalized = undefined;
378
- if (raw != null) {
379
- normalized = normalizeConfig(raw, errors);
310
+ if (!isSpecified(config, 'staticItems')) {
311
+ staticItems = [];
380
312
  }
381
- return { normalized: normalized ?? null, raw };
382
- }
313
+ else {
314
+ if (staticItems === null || staticItems === false) {
315
+ staticItems = [];
316
+ }
317
+ if (!Array.isArray(staticItems)) {
318
+ staticItems = [staticItems];
319
+ }
320
+ if (staticItems.every((x) => typeof x === 'string')) {
321
+ staticItems = staticItems.map((x, index) => {
322
+ if (x.includes('*')) {
323
+ let re;
324
+ try {
325
+ const regexp = globToRegExp(x, { globstar: true });
326
+ re = 're:' + String(regexp);
327
+ }
328
+ catch {
329
+ errors.push(`staticItems item at index ${index}, '${x}', cannot be parsed as glob pattern.`);
330
+ re = null;
331
+ }
332
+ return re;
333
+ }
334
+ return x;
335
+ });
336
+ }
337
+ else {
338
+ errors.push('staticItems, if specified, must be a string value, an array of string values, false, or null');
339
+ }
340
+ }
341
+ if (!isSpecified(config, 'allowedEncodings')) {
342
+ allowedEncodings = ['br', 'gzip'];
343
+ }
344
+ else if (allowedEncodings === null) {
345
+ allowedEncodings = [];
346
+ }
347
+ else {
348
+ if (!Array.isArray(allowedEncodings)) {
349
+ allowedEncodings = [allowedEncodings];
350
+ }
351
+ if (allowedEncodings.some((x) => x !== 'br' && x !== 'gzip')) {
352
+ errors.push(`allowedEncodings, if specified, must be null or an array and can only contain 'br' and 'gzip'.`);
353
+ }
354
+ }
355
+ if (!isSpecified(config, 'spaFile')) {
356
+ spaFile = null;
357
+ }
358
+ else {
359
+ if (typeof spaFile === 'string' || spaFile === null) {
360
+ // ok
361
+ }
362
+ else if (spaFile === false) {
363
+ spaFile = null;
364
+ }
365
+ else {
366
+ errors.push('spaFile, if specified, must be a string value, false, or null');
367
+ }
368
+ }
369
+ if (!isSpecified(config, 'notFoundPageFile')) {
370
+ notFoundPageFile = null;
371
+ }
372
+ else {
373
+ if (typeof notFoundPageFile === 'string' || notFoundPageFile === null) {
374
+ // ok
375
+ }
376
+ else if (notFoundPageFile === false) {
377
+ notFoundPageFile = null;
378
+ }
379
+ else {
380
+ errors.push('notFoundPageFile, if specified, must be a string value, false, or null');
381
+ }
382
+ }
383
+ if (!isSpecified(config, 'autoExt')) {
384
+ autoExt = [];
385
+ }
386
+ else {
387
+ if (Array.isArray(autoExt) && autoExt.every(e => typeof e === 'string')) {
388
+ // ok
389
+ }
390
+ else if (autoExt === false || autoExt === null) {
391
+ autoExt = [];
392
+ }
393
+ else if (typeof autoExt === 'string') {
394
+ autoExt = [autoExt];
395
+ }
396
+ else {
397
+ errors.push('autoExt, if specified, must be an array of string values, a string value, false, or null');
398
+ }
399
+ }
400
+ if (!isSpecified(config, 'autoIndex')) {
401
+ autoIndex = [];
402
+ }
403
+ else {
404
+ if (Array.isArray(autoIndex) && autoIndex.every(e => typeof e === 'string')) {
405
+ // ok
406
+ }
407
+ else if (autoIndex === false || autoIndex === null) {
408
+ autoIndex = [];
409
+ }
410
+ else if (typeof autoIndex === 'string') {
411
+ autoIndex = [autoIndex];
412
+ }
413
+ else {
414
+ errors.push('autoIndex, if specified, must be an array of string values, a string value, false, or null');
415
+ }
416
+ }
417
+ if (errors.length > 0) {
418
+ return null;
419
+ }
420
+ return {
421
+ publicDirPrefix,
422
+ staticItems,
423
+ allowedEncodings,
424
+ spaFile,
425
+ notFoundPageFile,
426
+ autoExt,
427
+ autoIndex,
428
+ };
429
+ });
@@ -1,5 +1,4 @@
1
- import { ContentTypeDef, ContentTypeTestResult } from "../types/content-types.js";
2
- export declare function getDefaultContentTypes(): ContentTypeDef[];
1
+ import { type ContentTypeDef, type ContentTypeTestResult } from '../../models/config/publish-content-config.js';
3
2
  export declare function mergeContentTypes(contentTypes: ContentTypeDef[]): ContentTypeDef[];
4
3
  export declare function testFileContentType(contentTypes: ContentTypeDef[] | null | undefined, assetKey: string): ContentTypeTestResult | null;
5
4
  //# sourceMappingURL=content-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-types.d.ts","sourceRoot":"","sources":["../../../src/cli/util/content-types.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC3B,MAAM,+CAA+C,CAAC;AAqCvD,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,cAAc,EAAE,oBAmD/D;AAED,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,cAAc,EAAE,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,qBAAqB,GAAG,IAAI,CAkBrI"}
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
1
5
  const defaultContentTypes = [
2
6
  // Text formats
3
7
  { test: /\.txt$/, contentType: 'text/plain', text: true },
@@ -9,7 +13,7 @@ const defaultContentTypes = [
9
13
  { test: /\.css$/, contentType: 'text/css', text: true },
10
14
  { test: /\.svg$/, contentType: 'image/svg+xml', text: true },
11
15
  // Binary formats
12
- { test: /\.bmp$/, contentType: 'image/bmp', text: false },
16
+ { test: /\.bmp$/, contentType: 'image/bmp', text: false, precompressAsset: true, },
13
17
  { test: /\.png$/, contentType: 'image/png', text: false },
14
18
  { test: /\.gif$/, contentType: 'image/gif', text: false },
15
19
  { test: /\.jp(e)?g$/, contentType: 'image/jpeg', text: false },
@@ -23,7 +27,7 @@ const defaultContentTypes = [
23
27
  { test: /\.mpeg$/, contentType: 'video/mpeg', text: false },
24
28
  { test: /\.webm$/, contentType: 'video/webm', text: false },
25
29
  { test: /\.pdf$/, contentType: 'application/pdf', text: false },
26
- { test: /\.tar$/, contentType: 'application/x-tar', text: false },
30
+ { test: /\.tar$/, contentType: 'application/x-tar', text: false, precompressAsset: true, },
27
31
  { test: /\.zip$/, contentType: 'application/zip', text: false },
28
32
  { test: /\.eot$/, contentType: 'application/vnd.ms-fontobject', text: false },
29
33
  { test: /\.otf$/, contentType: 'font/otf', text: false },
@@ -31,9 +35,6 @@ const defaultContentTypes = [
31
35
  { test: /\.woff$/, contentType: 'font/woff', text: false },
32
36
  { test: /\.woff2$/, contentType: 'font/woff2', text: false },
33
37
  ];
34
- export function getDefaultContentTypes() {
35
- return defaultContentTypes;
36
- }
37
38
  export function mergeContentTypes(contentTypes) {
38
39
  const finalContentTypes = [];
39
40
  if (!Array.isArray(contentTypes)) {
@@ -86,7 +87,11 @@ export function testFileContentType(contentTypes, assetKey) {
86
87
  matched = contentType.test(assetKey);
87
88
  }
88
89
  if (matched) {
89
- return { contentType: contentType.contentType, text: Boolean(contentType.text ?? false) };
90
+ return {
91
+ contentType: contentType.contentType,
92
+ text: Boolean(contentType.text ?? false),
93
+ precompressAsset: Boolean(contentType.precompressAsset ?? contentType.text ?? false)
94
+ };
90
95
  }
91
96
  }
92
97
  return null;
@@ -1,6 +1,6 @@
1
- export type NormalizeAction<T> = (value: any, errors: string[]) => T | null;
2
- export declare function buildNormalizeFunctionForObject<TObject>(action: NormalizeAction<TObject>): (obj: any, errCtx?: string[]) => TObject | null;
3
- export declare function buildNormalizeFunctionForArray<TEntry>(action: NormalizeAction<TEntry>): (obj: any, errCtx?: string[]) => TEntry[] | null;
1
+ export type NormalizeAction<T> = (value: Record<string, any>, errors: string[]) => T | null;
2
+ export declare function buildNormalizeFunctionForObject<TObject>(action: NormalizeAction<TObject>): (obj: unknown, errCtx?: string[]) => TObject | null;
3
+ export declare function buildNormalizeFunctionForArray<TEntry>(action: NormalizeAction<TEntry>): (obj: unknown, errCtx?: string[]) => TEntry[] | null;
4
4
  export declare function isStringAndNotEmpty(str: unknown): str is string;
5
5
  export declare function isSpecified(obj: any, key: string): boolean;
6
6
  export declare function applyDefaults<T extends Record<string, unknown>>(data: Partial<T> | null, defaults: T): T & Partial<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/cli/util/data.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;AAE5E,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,SAE1E,GAAG,WAAU,MAAM,EAAE,KAAQ,OAAO,GAAG,IAAI,CAmBzD;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,SAEvE,GAAG,WAAU,MAAM,EAAE,KAAQ,MAAM,EAAE,GAAG,IAAI,CAgC1D;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAE/D;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAC,GAAG,EAAE,GAAG,EAAE,MAAM,WAE/C;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,kBAYpG"}
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/cli/util/data.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;AAE5F,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,IAE/E,KAAK,OAAO,EAAE,SAAQ,MAAM,EAAO,KAAG,OAAO,GAAG,IAAI,CAmB7D;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,IAE5E,KAAK,OAAO,EAAE,SAAQ,MAAM,EAAO,KAAG,MAAM,EAAE,GAAG,IAAI,CAgC9D;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAE/D;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAC,GAAG,EAAE,GAAG,EAAE,MAAM,WAE/C;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC,kBAYpG"}
@@ -1,7 +1,11 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
1
5
  export function buildNormalizeFunctionForObject(action) {
2
6
  return (obj, errCtx = []) => {
3
- if (obj == null) {
4
- errCtx.push('obj cannot be null.');
7
+ if (obj == null || typeof obj !== 'object') {
8
+ errCtx.push('obj must be an object.');
5
9
  return null;
6
10
  }
7
11
  const errors = [];
@@ -1,11 +1,19 @@
1
1
  export interface FilenameTest {
2
2
  test(name: string): boolean;
3
3
  }
4
- export type GetFilesOpts = {
4
+ export type EnumerateFilesOpts = {
5
5
  publicDirRoot: string;
6
6
  excludeDirs: FilenameTest[];
7
7
  excludeDotFiles: boolean;
8
8
  includeWellKnown: boolean;
9
9
  };
10
- export declare function getFiles(dir: string, opts: GetFilesOpts): string[];
10
+ export declare function enumerateFiles(opts: EnumerateFilesOpts): string[];
11
+ export declare function getFileSize(filePath: string): number;
12
+ export declare function directoryExists(dirPath: string): boolean;
13
+ export declare function calculateFileSizeAndHash(filePath: string): Promise<{
14
+ size: number;
15
+ hash: string;
16
+ }>;
17
+ export declare function rootRelative(itemPath: string): string;
18
+ export declare function dotRelative(from: string | null, to: string): string;
11
19
  //# sourceMappingURL=files.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/cli/util/files.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,YAAY,EAAE,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,YAIvD"}
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/cli/util/files.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,YAAY,EAAE,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,YAItD;AAoCD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,UAG3C;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,WAU9C;AAED,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,MAAM;UAQlC,MAAM;UAAQ,MAAM;GAgBhD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,UAE5C;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,UAG1D"}