@fastly/compute-js-static-publish 8.0.0 → 8.1.0-beta.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.
Files changed (251) hide show
  1. package/DOCUMENTATION.md +1984 -0
  2. package/README.md +11 -4
  3. package/README.short.md +11 -4
  4. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  5. package/build/cli/cli/commands/manage/clean.js +12 -7
  6. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
  7. package/build/cli/cli/commands/manage/collections/delete.js +29 -13
  8. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
  9. package/build/cli/cli/commands/manage/collections/index.js +6 -1
  10. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
  11. package/build/cli/cli/commands/manage/collections/list.js +47 -7
  12. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  13. package/build/cli/cli/commands/manage/collections/promote.js +67 -20
  14. package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
  15. package/build/cli/cli/commands/manage/collections/update-expiration.js +10 -11
  16. package/build/cli/cli/commands/manage/deploy.d.ts +2 -0
  17. package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -0
  18. package/build/cli/cli/commands/manage/deploy.js +194 -0
  19. package/build/cli/cli/commands/manage/dev.d.ts +2 -0
  20. package/build/cli/cli/commands/manage/dev.d.ts.map +1 -0
  21. package/build/cli/cli/commands/manage/dev.js +77 -0
  22. package/build/cli/cli/commands/manage/eject.d.ts +2 -0
  23. package/build/cli/cli/commands/manage/eject.d.ts.map +1 -0
  24. package/build/cli/cli/commands/manage/eject.js +155 -0
  25. package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
  26. package/build/cli/cli/commands/manage/index.js +37 -1
  27. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  28. package/build/cli/cli/commands/manage/publish-content.js +85 -35
  29. package/build/cli/cli/commands/manage/status.d.ts +2 -0
  30. package/build/cli/cli/commands/manage/status.d.ts.map +1 -0
  31. package/build/cli/cli/commands/manage/status.js +162 -0
  32. package/build/cli/cli/commands/manage/template/index.d.ts +2 -0
  33. package/build/cli/cli/commands/manage/template/index.d.ts.map +1 -0
  34. package/build/cli/cli/commands/manage/template/index.js +42 -0
  35. package/build/cli/cli/commands/manage/template/init.d.ts +13 -0
  36. package/build/cli/cli/commands/manage/template/init.d.ts.map +1 -0
  37. package/build/cli/cli/commands/manage/template/init.js +172 -0
  38. package/build/cli/cli/commands/manage/upgrade.d.ts +2 -0
  39. package/build/cli/cli/commands/manage/upgrade.d.ts.map +1 -0
  40. package/build/cli/cli/commands/manage/upgrade.js +59 -0
  41. package/build/cli/cli/commands/run-dev-watch.d.ts +8 -0
  42. package/build/cli/cli/commands/run-dev-watch.d.ts.map +1 -0
  43. package/build/cli/cli/commands/run-dev-watch.js +41 -0
  44. package/build/cli/cli/commands/run-template-hook.d.ts +2 -0
  45. package/build/cli/cli/commands/run-template-hook.d.ts.map +1 -0
  46. package/build/cli/cli/commands/run-template-hook.js +28 -0
  47. package/build/cli/cli/commands/scaffold/app-template.d.ts +17 -0
  48. package/build/cli/cli/commands/scaffold/app-template.d.ts.map +1 -0
  49. package/build/cli/cli/commands/scaffold/app-template.js +54 -0
  50. package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts +5 -0
  51. package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts.map +1 -0
  52. package/build/cli/cli/commands/scaffold/fastly-toml-sections.js +154 -0
  53. package/build/cli/cli/commands/scaffold/generate-app.d.ts +47 -0
  54. package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -0
  55. package/build/cli/cli/commands/scaffold/generate-app.js +164 -0
  56. package/build/cli/cli/commands/scaffold/index.d.ts +6 -0
  57. package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
  58. package/build/cli/cli/commands/scaffold/index.js +239 -300
  59. package/build/cli/cli/commands/scaffold/render.d.ts +7 -0
  60. package/build/cli/cli/commands/scaffold/render.d.ts.map +1 -0
  61. package/build/cli/cli/commands/scaffold/render.js +72 -0
  62. package/build/cli/cli/hono/build.d.ts +43 -0
  63. package/build/cli/cli/hono/build.d.ts.map +1 -0
  64. package/build/cli/cli/hono/build.js +297 -0
  65. package/build/cli/cli/index.js +98 -5
  66. package/build/cli/cli/managed/app.d.ts +21 -0
  67. package/build/cli/cli/managed/app.d.ts.map +1 -0
  68. package/build/cli/cli/managed/app.js +162 -0
  69. package/build/cli/cli/managed/command-helpers.d.ts +6 -0
  70. package/build/cli/cli/managed/command-helpers.d.ts.map +1 -0
  71. package/build/cli/cli/managed/command-helpers.js +81 -0
  72. package/build/cli/cli/managed/eject.d.ts +6 -0
  73. package/build/cli/cli/managed/eject.d.ts.map +1 -0
  74. package/build/cli/cli/managed/eject.js +68 -0
  75. package/build/cli/cli/managed/fastly-service.d.ts +8 -0
  76. package/build/cli/cli/managed/fastly-service.d.ts.map +1 -0
  77. package/build/cli/cli/managed/fastly-service.js +21 -0
  78. package/build/cli/cli/managed/fingerprint.d.ts +13 -0
  79. package/build/cli/cli/managed/fingerprint.d.ts.map +1 -0
  80. package/build/cli/cli/managed/fingerprint.js +60 -0
  81. package/build/cli/cli/managed/lockfile.d.ts +31 -0
  82. package/build/cli/cli/managed/lockfile.d.ts.map +1 -0
  83. package/build/cli/cli/managed/lockfile.js +62 -0
  84. package/build/cli/cli/managed/project-edit.d.ts +3 -0
  85. package/build/cli/cli/managed/project-edit.d.ts.map +1 -0
  86. package/build/cli/cli/managed/project-edit.js +35 -0
  87. package/build/cli/cli/managed/project-file.d.ts +16 -0
  88. package/build/cli/cli/managed/project-file.d.ts.map +1 -0
  89. package/build/cli/cli/managed/project-file.js +119 -0
  90. package/build/cli/cli/managed/template-init.d.ts +12 -0
  91. package/build/cli/cli/managed/template-init.d.ts.map +1 -0
  92. package/build/cli/cli/managed/template-init.js +120 -0
  93. package/build/cli/cli/managed/version-check.d.ts +25 -0
  94. package/build/cli/cli/managed/version-check.d.ts.map +1 -0
  95. package/build/cli/cli/managed/version-check.js +84 -0
  96. package/build/cli/cli/storage/kv-store-local-provider.d.ts +1 -0
  97. package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
  98. package/build/cli/cli/storage/kv-store-local-provider.js +6 -3
  99. package/build/cli/cli/storage/kv-store-provider.d.ts +2 -1
  100. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
  101. package/build/cli/cli/storage/kv-store-provider.js +17 -6
  102. package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
  103. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  104. package/build/cli/cli/storage/s3-storage-provider.js +8 -2
  105. package/build/cli/cli/storage/storage-provider.d.ts +4 -0
  106. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
  107. package/build/cli/cli/storage/storage-provider.js +32 -0
  108. package/build/cli/cli/util/api-token.d.ts +2 -1
  109. package/build/cli/cli/util/api-token.d.ts.map +1 -1
  110. package/build/cli/cli/util/api-token.js +38 -3
  111. package/build/cli/cli/util/collection-name.d.ts +3 -0
  112. package/build/cli/cli/util/collection-name.d.ts.map +1 -0
  113. package/build/cli/cli/util/collection-name.js +24 -0
  114. package/build/cli/cli/util/collection-selection-flags.d.ts +13 -0
  115. package/build/cli/cli/util/collection-selection-flags.d.ts.map +1 -0
  116. package/build/cli/cli/util/collection-selection-flags.js +131 -0
  117. package/build/cli/cli/util/config.d.ts +13 -0
  118. package/build/cli/cli/util/config.d.ts.map +1 -1
  119. package/build/cli/cli/util/config.js +172 -38
  120. package/build/cli/cli/util/data.d.ts.map +1 -1
  121. package/build/cli/cli/util/global-options.d.ts +13 -0
  122. package/build/cli/cli/util/global-options.d.ts.map +1 -0
  123. package/build/cli/cli/util/global-options.js +53 -0
  124. package/build/cli/cli/util/kv-store-items.d.ts +1 -0
  125. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
  126. package/build/cli/cli/util/kv-store-items.js +16 -40
  127. package/build/cli/cli/util/kv-store-local-server.d.ts +1 -1
  128. package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -1
  129. package/build/cli/cli/util/kv-store-local-server.js +4 -2
  130. package/build/cli/cli/util/output.d.ts +31 -0
  131. package/build/cli/cli/util/output.d.ts.map +1 -0
  132. package/build/cli/cli/util/output.js +139 -0
  133. package/build/cli/cli/util/package.d.ts +3 -0
  134. package/build/cli/cli/util/package.d.ts.map +1 -1
  135. package/build/cli/cli/util/package.js +12 -0
  136. package/build/cli/cli/util/progress.d.ts +11 -0
  137. package/build/cli/cli/util/progress.d.ts.map +1 -0
  138. package/build/cli/cli/util/progress.js +32 -0
  139. package/build/cli/cli/util/purge.d.ts +15 -3
  140. package/build/cli/cli/util/purge.d.ts.map +1 -1
  141. package/build/cli/cli/util/purge.js +23 -10
  142. package/build/cli/cli/util/resources.d.ts +2 -0
  143. package/build/cli/cli/util/resources.d.ts.map +1 -0
  144. package/build/cli/cli/util/resources.js +8 -0
  145. package/build/cli/cli/util/service-id.d.ts +1 -0
  146. package/build/cli/cli/util/service-id.d.ts.map +1 -1
  147. package/build/cli/cli/util/service-id.js +5 -1
  148. package/build/cli/cli/util/variants.d.ts.map +1 -1
  149. package/build/cli/models/assets/index.d.ts +6 -0
  150. package/build/cli/models/assets/index.d.ts.map +1 -1
  151. package/build/cli/models/assets/index.js +24 -0
  152. package/build/cli/models/collections/index.d.ts +3 -0
  153. package/build/cli/models/collections/index.d.ts.map +1 -0
  154. package/build/cli/models/collections/index.js +15 -0
  155. package/build/cli/models/compression/index.d.ts +1 -1
  156. package/build/cli/models/compression/index.d.ts.map +1 -1
  157. package/build/cli/models/config/collection-selection.d.ts +55 -0
  158. package/build/cli/models/config/collection-selection.d.ts.map +1 -0
  159. package/build/cli/models/config/collection-selection.js +238 -0
  160. package/build/cli/models/config/item-patterns.d.ts +4 -0
  161. package/build/cli/models/config/item-patterns.d.ts.map +1 -0
  162. package/build/cli/models/config/item-patterns.js +43 -0
  163. package/build/cli/models/config/publish-content-config.d.ts +6 -1
  164. package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
  165. package/build/cli/models/config/static-publish-project.d.ts +23 -0
  166. package/build/cli/models/config/static-publish-project.d.ts.map +1 -0
  167. package/build/cli/models/config/static-publish-project.js +11 -0
  168. package/build/cli/models/config/static-publish-rc.d.ts +25 -0
  169. package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
  170. package/build/cli/models/config/static-publish-rc.js +31 -0
  171. package/build/cli/models/config/template-settings.d.ts +10 -0
  172. package/build/cli/models/config/template-settings.d.ts.map +1 -0
  173. package/build/cli/models/config/template-settings.js +72 -0
  174. package/build/cli/models/server/index.d.ts.map +1 -1
  175. package/build/cli/models/server/index.js +6 -2
  176. package/build/server/hono/extensions.d.ts +48 -0
  177. package/build/server/hono/extensions.d.ts.map +1 -0
  178. package/build/server/hono/extensions.js +65 -0
  179. package/build/server/hono/index.d.ts +30 -0
  180. package/build/server/hono/index.d.ts.map +1 -0
  181. package/build/server/hono/index.js +72 -0
  182. package/build/server/hono/path.d.ts +7 -0
  183. package/build/server/hono/path.d.ts.map +1 -0
  184. package/build/server/hono/path.js +32 -0
  185. package/build/server/models/assets/index.d.ts +6 -0
  186. package/build/server/models/assets/index.d.ts.map +1 -1
  187. package/build/server/models/assets/index.js +24 -0
  188. package/build/server/models/collections/index.d.ts +3 -0
  189. package/build/server/models/collections/index.d.ts.map +1 -0
  190. package/build/server/models/collections/index.js +15 -0
  191. package/build/server/models/compression/index.d.ts +1 -1
  192. package/build/server/models/compression/index.d.ts.map +1 -1
  193. package/build/server/models/config/collection-selection.d.ts +55 -0
  194. package/build/server/models/config/collection-selection.d.ts.map +1 -0
  195. package/build/server/models/config/collection-selection.js +238 -0
  196. package/build/server/models/config/item-patterns.d.ts +4 -0
  197. package/build/server/models/config/item-patterns.d.ts.map +1 -0
  198. package/build/server/models/config/item-patterns.js +43 -0
  199. package/build/server/models/config/publish-content-config.d.ts +6 -1
  200. package/build/server/models/config/publish-content-config.d.ts.map +1 -1
  201. package/build/server/models/config/static-publish-project.d.ts +23 -0
  202. package/build/server/models/config/static-publish-project.d.ts.map +1 -0
  203. package/build/server/models/config/static-publish-project.js +11 -0
  204. package/build/server/models/config/static-publish-rc.d.ts +25 -0
  205. package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
  206. package/build/server/models/config/static-publish-rc.js +31 -0
  207. package/build/server/models/server/index.d.ts.map +1 -1
  208. package/build/server/models/server/index.js +6 -2
  209. package/build/server/server/collection-selection/index.d.ts +11 -0
  210. package/build/server/server/collection-selection/index.d.ts.map +1 -0
  211. package/build/server/server/collection-selection/index.js +192 -0
  212. package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -1
  213. package/build/server/server/collection-selector/from-cookie.js +6 -8
  214. package/build/server/server/collection-selector/from-request.d.ts.map +1 -1
  215. package/build/server/server/index.d.ts +4 -1
  216. package/build/server/server/index.d.ts.map +1 -1
  217. package/build/server/server/index.js +3 -1
  218. package/build/server/server/publisher-server/accept-html.d.ts +2 -0
  219. package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
  220. package/build/server/server/publisher-server/accept-html.js +50 -0
  221. package/build/server/server/publisher-server/index.d.ts +59 -6
  222. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  223. package/build/server/server/publisher-server/index.js +370 -131
  224. package/build/server/server/publisher-server/response-cache.d.ts +3 -0
  225. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
  226. package/build/server/server/publisher-server/response-cache.js +24 -1
  227. package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
  228. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
  229. package/build/server/server/storage/storage-provider.d.ts.map +1 -1
  230. package/build/server/server/util/body-length.d.ts.map +1 -1
  231. package/build/server/server/util/server-timing.d.ts.map +1 -1
  232. package/package.json +23 -4
  233. package/resources/app/fastly.toml.njk +58 -0
  234. package/resources/app/gitignore.njk +9 -0
  235. package/resources/app/publish-content.config.from-project.js.njk +9 -0
  236. package/resources/app/publish-content.config.js.njk +35 -0
  237. package/resources/app/static-publish.project.js.njk +83 -0
  238. package/resources/app/static-publish.rc.js.njk +43 -0
  239. package/resources/template-init/hono/_example.ts +22 -0
  240. package/resources/template-init/hono/tsconfig.json +17 -0
  241. package/resources/templates/hono/package-lock.json +4123 -0
  242. package/resources/templates/hono/package.json +15 -0
  243. package/resources/templates/hono/scripts/template_postinstall.js +10 -0
  244. package/resources/templates/hono/scripts/template_prebuild.js +8 -0
  245. package/resources/templates/hono/scripts/template_watch.js +15 -0
  246. package/resources/templates/hono/src/hono-extensions.generated.d.ts +5 -0
  247. package/resources/templates/hono/src/index.ts +53 -0
  248. package/resources/templates/hono/tsconfig.json +17 -0
  249. package/resources/templates/plain/package-lock.json +4088 -0
  250. package/resources/templates/plain/package.json +10 -0
  251. package/resources/templates/plain/src/index.js +34 -0
@@ -37,3 +37,35 @@ export async function loadStorageProviderFromStaticPublishRc(config, context) {
37
37
  }
38
38
  throw new Error('Static Publisher Error: Invalid static-publish.rc.js, storage mode not recognized, or could not instantiate store provider.');
39
39
  }
40
+ // Returns true if storage has the variant with the key `variantKey`, which has
41
+ // `size` bytes in `numChunks` chunks. For a variant in more than one chunk, it
42
+ // also compares the stored size of each chunk with its expected size. It removes
43
+ // a chunk that has a different size, or that is not in storage now, from
44
+ // existingKeys, so that applyBatch() uploads the chunk again.
45
+ export async function isVariantInStorage(storageProvider, existingKeys, variantKey, size, numChunks) {
46
+ const chunkKeys = Array.from({ length: numChunks }, (_, chunkIndex) => chunkIndex === 0 ? variantKey : `${variantKey}_${chunkIndex}`);
47
+ if (!chunkKeys.every(key => existingKeys.has(key))) {
48
+ return false;
49
+ }
50
+ if (numChunks === 1) {
51
+ return true;
52
+ }
53
+ const expectedSizes = storageProvider.calculateChunkSizes(size);
54
+ const entries = await Promise.all(chunkKeys.map(key => storageProvider.getStorageEntryInfo(key)));
55
+ let found = true;
56
+ for (const [chunkIndex, key] of chunkKeys.entries()) {
57
+ const entry = entries[chunkIndex];
58
+ if (entry == null) {
59
+ existingKeys.delete(key);
60
+ found = false;
61
+ continue;
62
+ }
63
+ const storedSize = entry.size;
64
+ if (storedSize != null && storedSize !== expectedSizes[chunkIndex]) {
65
+ console.log(` ‼️ Chunk "${key}" in storage has ${storedSize} bytes, but it must have ${expectedSizes[chunkIndex]} bytes. It will be uploaded again.`);
66
+ existingKeys.delete(key);
67
+ found = false;
68
+ }
69
+ }
70
+ return found;
71
+ }
@@ -10,8 +10,9 @@ export type LoadApiParams = {
10
10
  };
11
11
  export declare function loadApiToken(params: LoadApiParams): LoadApiTokenResult | null;
12
12
  export declare class FetchError extends Error {
13
- constructor(message: string, status: number);
13
+ constructor(message: string, status: number, detail?: string);
14
14
  status: number;
15
+ detail?: string;
15
16
  }
16
17
  export declare function callFastlyApi(fastlyApiContext: FastlyApiContext, endpoint: string, operationName: string, queryParams?: URLSearchParams | null, requestInit?: RequestInit): Promise<Response>;
17
18
  //# sourceMappingURL=api-token.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAyB7E;AAaD,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK3C,MAAM,EAAE,MAAM,CAAC;CAChB;AAWD,wBAAsB,aAAa,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,eAAe,GAAG,IAAI,EACpC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,QAAQ,CAAC,CAqCnB"}
1
+ {"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAyB7E;AAaD,qBAAa,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAK3D;IACD,MAAM,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAWD,wBAAsB,aAAa,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,eAAe,GAAG,IAAI,EACpC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,QAAQ,CAAC,CAuCnB"}
@@ -34,10 +34,11 @@ const RETRYABLE_STATUS_CODES = [
34
34
  504, // Gateway Timeout
35
35
  ];
36
36
  export class FetchError extends Error {
37
- constructor(message, status) {
37
+ constructor(message, status, detail) {
38
38
  super(message);
39
39
  this.name = 'FetchError';
40
40
  this.status = status;
41
+ this.detail = detail;
41
42
  }
42
43
  }
43
44
  function isReadableStream(data) {
@@ -74,10 +75,44 @@ export async function callFastlyApi(fastlyApiContext, endpoint, operationName, q
74
75
  }
75
76
  }
76
77
  if (!response.ok) {
78
+ const detail = await readApiErrorDetail(response);
79
+ const status = `${response.status}${detail != null ? ` ${detail}` : ''}`;
77
80
  if (!RETRYABLE_STATUS_CODES.includes(response.status)) {
78
- throw new FetchError(`${operationName} failed: ${response.status}`, response.status);
81
+ throw new FetchError(`${operationName} failed: ${status}`, response.status, detail);
79
82
  }
80
- throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${response.status}`, response.status));
83
+ throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${status}`, response.status, detail));
81
84
  }
82
85
  return response;
83
86
  }
87
+ // The Content-Type of an error response tells which fields describe the error:
88
+ // - application/json: the Fastly API fields msg and detail, for example
89
+ // {"msg":"Record not found","detail":"Cannot find service"}.
90
+ // - application/problem+json (RFC 9457): the fields title and detail.
91
+ // - Other types, or JSON that is not valid: the start of the text.
92
+ async function readApiErrorDetail(response) {
93
+ let text;
94
+ try {
95
+ text = (await response.text()).trim();
96
+ }
97
+ catch {
98
+ return undefined;
99
+ }
100
+ const mediaType = response.headers.get('content-type')?.split(';')[0].trim().toLowerCase();
101
+ const fields = mediaType === 'application/json' ? ['msg', 'detail'] :
102
+ mediaType === 'application/problem+json' ? ['title', 'detail'] :
103
+ null;
104
+ if (fields != null) {
105
+ let json;
106
+ try {
107
+ json = JSON.parse(text);
108
+ }
109
+ catch {
110
+ json = undefined;
111
+ }
112
+ if (json !== undefined) {
113
+ const parts = fields.map(field => json?.[field]).filter(x => typeof x === 'string' && x !== '');
114
+ return parts.length > 0 ? parts.join(': ') : undefined;
115
+ }
116
+ }
117
+ return text !== '' ? text.slice(0, 200) : undefined;
118
+ }
@@ -0,0 +1,3 @@
1
+ import { type StorageProvider } from '../storage/storage-provider.js';
2
+ export declare function checkCollectionNameForWrite(storageProvider: StorageProvider, publishId: string, collectionName: string): Promise<boolean>;
3
+ //# sourceMappingURL=collection-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection-name.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/collection-name.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAOtE,wBAAsB,2BAA2B,CAC/C,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC,CAelB"}
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { COLLECTION_NAME_RULE, isValidCollectionName } from '../../models/collections/index.js';
6
+ import { fail } from './output.js';
7
+ // Checks a collection name that a command writes to. A new collection must
8
+ // have a valid name. A collection that exists continues to work with a name
9
+ // that breaks the rule, with a warning.
10
+ // Returns false (and fails the command) if the command must stop.
11
+ export async function checkCollectionNameForWrite(storageProvider, publishId, collectionName) {
12
+ if (isValidCollectionName(collectionName)) {
13
+ return true;
14
+ }
15
+ const indexKey = `${publishId}_index_${collectionName}`;
16
+ const indexEntry = await storageProvider.getStorageEntryInfo(indexKey);
17
+ if (indexEntry != null) {
18
+ console.warn(`⚠️ Warning: Collection name '${collectionName}' is not valid. ${COLLECTION_NAME_RULE}`);
19
+ console.warn(` * The collection exists, so it continues to work. Use a valid name for new collections.`);
20
+ return true;
21
+ }
22
+ fail('collection-name-invalid', `Collection name '${collectionName}' is not valid. ${COLLECTION_NAME_RULE}`);
23
+ return false;
24
+ }
@@ -0,0 +1,13 @@
1
+ import { type CollectionSelection } from '../../models/config/collection-selection.js';
2
+ export type CollectionSelectionFlags = {
3
+ sources?: string[];
4
+ allow?: string[];
5
+ onMissing?: string;
6
+ noindex?: string;
7
+ };
8
+ export declare const COLLECTION_SELECTION_FLAGS_HELP = " --collection-selection <source> Select the collection of a request, for example for\n previews. Can be repeated; the sources are tried in order.\n host:<pattern> host:{collection}.preview.example.com\n path:<prefix>[,sticky] path:/_preview/{collection},sticky\n query:<param>[,sticky] query:collection,sticky\n cookie[:<name>][,maxAge=<seconds>][,activatePath=<path>][,resetPath=<path>]\n header:<name> header:x-publisher-collection\n 'sticky' also sets the cookie of the cookie source, so it needs a cookie source.\n --collection-allow <patterns> The collections that can be selected, for example \"pr-*,staging\".\n Default: any collection.\n --collection-on-missing <value> When the selected collection is not published or has\n expired: 'not-found' (default: a 404 response) or\n 'default' (serve the default collection).\n --collection-noindex <true|false> Add 'X-Robots-Tag: noindex' to the responses of a collection\n that is not the default collection. Default: true.";
9
+ export declare function collectionSelectionFromFlags(flags: CollectionSelectionFlags): {
10
+ collectionSelection: CollectionSelection | undefined;
11
+ errors: string[];
12
+ };
13
+ //# sourceMappingURL=collection-selection-flags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection-selection-flags.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/collection-selection-flags.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,mBAAmB,EAIzB,MAAM,6CAA6C,CAAC;AAcrD,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,+BAA+B,y8CAe+C,CAAC;AA0E5F,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,wBAAwB,GAAG;IAC7E,mBAAmB,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACrD,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAqCA"}
@@ -0,0 +1,131 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { validateCollectionSelection, } from '../../models/config/collection-selection.js';
6
+ export const COLLECTION_SELECTION_FLAGS_HELP = `\
7
+ --collection-selection <source> Select the collection of a request, for example for
8
+ previews. Can be repeated; the sources are tried in order.
9
+ host:<pattern> host:{collection}.preview.example.com
10
+ path:<prefix>[,sticky] path:/_preview/{collection},sticky
11
+ query:<param>[,sticky] query:collection,sticky
12
+ cookie[:<name>][,maxAge=<seconds>][,activatePath=<path>][,resetPath=<path>]
13
+ header:<name> header:x-publisher-collection
14
+ 'sticky' also sets the cookie of the cookie source, so it needs a cookie source.
15
+ --collection-allow <patterns> The collections that can be selected, for example "pr-*,staging".
16
+ Default: any collection.
17
+ --collection-on-missing <value> When the selected collection is not published or has
18
+ expired: 'not-found' (default: a 404 response) or
19
+ 'default' (serve the default collection).
20
+ --collection-noindex <true|false> Add 'X-Robots-Tag: noindex' to the responses of a collection
21
+ that is not the default collection. Default: true.`;
22
+ function parseSource(spec, errors) {
23
+ const [head, ...options] = spec.split(',').map(x => x.trim());
24
+ const colon = head.indexOf(':');
25
+ const type = colon === -1 ? head : head.slice(0, colon);
26
+ const value = colon === -1 ? undefined : head.slice(colon + 1);
27
+ const needValue = (what) => {
28
+ if (value == null || value === '') {
29
+ errors.push(`--collection-selection ${type}: give the ${what}, for example '${type}:<${what}>'.`);
30
+ return false;
31
+ }
32
+ return true;
33
+ };
34
+ const sticky = () => {
35
+ let result;
36
+ for (const option of options) {
37
+ if (option === 'sticky') {
38
+ result = 'cookie';
39
+ }
40
+ else {
41
+ errors.push(`--collection-selection ${type}: unknown option '${option}'.`);
42
+ }
43
+ }
44
+ return result;
45
+ };
46
+ const noOptions = () => {
47
+ for (const option of options) {
48
+ errors.push(`--collection-selection ${type}: unknown option '${option}'.`);
49
+ }
50
+ };
51
+ switch (type) {
52
+ case 'host':
53
+ noOptions();
54
+ return needValue('pattern') ? { type, pattern: value } : null;
55
+ case 'path': {
56
+ const s = sticky();
57
+ return needValue('prefix') ? { type, prefix: value, ...(s != null ? { sticky: s } : {}) } : null;
58
+ }
59
+ case 'query': {
60
+ const s = sticky();
61
+ return needValue('param') ? { type, param: value, ...(s != null ? { sticky: s } : {}) } : null;
62
+ }
63
+ case 'header':
64
+ noOptions();
65
+ return needValue('name') ? { type, name: value } : null;
66
+ case 'cookie': {
67
+ const source = { type };
68
+ if (value != null && value !== '') {
69
+ source.cookieName = value;
70
+ }
71
+ for (const option of options) {
72
+ const eq = option.indexOf('=');
73
+ const key = eq === -1 ? option : option.slice(0, eq);
74
+ const optionValue = eq === -1 ? '' : option.slice(eq + 1);
75
+ if (key === 'maxAge' && /^\d+$/.test(optionValue)) {
76
+ source.maxAge = Number(optionValue);
77
+ }
78
+ else if (key === 'activatePath' || key === 'resetPath') {
79
+ source[key] = optionValue;
80
+ }
81
+ else {
82
+ errors.push(`--collection-selection cookie: unknown option, or a value that is not valid: '${option}'.`);
83
+ }
84
+ }
85
+ return source;
86
+ }
87
+ default:
88
+ errors.push(`--collection-selection: unknown source '${type}'. Use host, path, query, cookie, or header.`);
89
+ return null;
90
+ }
91
+ }
92
+ // Returns the collectionSelection from the flags (undefined if no flag is set),
93
+ // and the errors.
94
+ export function collectionSelectionFromFlags(flags) {
95
+ const errors = [];
96
+ const sources = flags.sources ?? [];
97
+ if (sources.length === 0) {
98
+ if (flags.allow != null || flags.onMissing != null || flags.noindex != null) {
99
+ errors.push('--collection-allow, --collection-on-missing, and --collection-noindex need --collection-selection.');
100
+ }
101
+ return { collectionSelection: undefined, errors };
102
+ }
103
+ const collectionSelection = { sources: [] };
104
+ for (const spec of sources) {
105
+ const source = parseSource(spec, errors);
106
+ if (source != null) {
107
+ collectionSelection.sources.push(source);
108
+ }
109
+ }
110
+ if (flags.allow != null) {
111
+ collectionSelection.allow = flags.allow.flatMap(x => x.split(',')).map(x => x.trim()).filter(x => x !== '');
112
+ }
113
+ if (flags.onMissing != null) {
114
+ collectionSelection.onMissing = flags.onMissing;
115
+ }
116
+ if (flags.noindex != null) {
117
+ if (flags.noindex === 'true') {
118
+ collectionSelection.noindex = true;
119
+ }
120
+ else if (flags.noindex === 'false') {
121
+ collectionSelection.noindex = false;
122
+ }
123
+ else {
124
+ errors.push(`--collection-noindex must be 'true' or 'false'.`);
125
+ }
126
+ }
127
+ if (errors.length === 0) {
128
+ errors.push(...validateCollectionSelection(collectionSelection));
129
+ }
130
+ return { collectionSelection: errors.length === 0 ? collectionSelection : undefined, errors };
131
+ }
@@ -1,12 +1,25 @@
1
1
  import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
2
+ import { type StaticPublishProjectManaged } from '../../models/config/static-publish-project.js';
2
3
  import { type PublishContentConfigNormalized } from '../../models/config/publish-content-config.js';
3
4
  import { type PublisherServerConfigNormalized } from '../../models/config/publisher-server-config.js';
4
5
  export declare class LoadConfigError extends Error {
5
6
  errors: string[];
6
7
  constructor(configFilePath: string, errors: string[]);
7
8
  }
9
+ export type ProjectMode = 'managed' | 'ejected' | 'scaffold' | 'conflict';
10
+ export declare function detectProjectMode(dir?: string): ProjectMode;
11
+ export declare function getComputeAppDir(): string;
12
+ export declare function configFileName(): string;
13
+ export type StaticPublishProjectNormalized = {
14
+ rc: StaticPublishRc;
15
+ publishContent: unknown;
16
+ managed: StaticPublishProjectManaged;
17
+ };
18
+ export declare const normalizeProjectManaged: (obj: unknown, errCtx?: string[]) => StaticPublishProjectManaged | null;
19
+ export declare function loadProjectFile(): Promise<StaticPublishProjectNormalized>;
8
20
  export declare function loadStaticPublisherRcFile(): Promise<StaticPublishRc>;
9
21
  export declare const normalizeStaticPublisherRc: (obj: unknown, errCtx?: string[]) => StaticPublishRc | null;
22
+ export declare function loadPublishContentConfig(configFile: string | undefined): Promise<PublishContentConfigNormalized>;
10
23
  export declare function loadPublishContentConfigFile(configFile: string): Promise<PublishContentConfigNormalized>;
11
24
  export declare const normalizePublishContentConfig: (obj: unknown, errCtx?: string[]) => PublishContentConfigNormalized | null;
12
25
  export declare const normalizePublisherServerConfig: (obj: unknown, errCtx?: string[]) => PublisherServerConfigNormalized | null;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/config.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,0CAA0C,CAAC;AAOlD,OAAO,EACL,KAAK,8BAA8B,EAEpC,MAAM,+CAA+C,CAAC;AAOvD,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AAEtG,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;gBAEL,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;CAIrD;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,eAAe,CAAC,CA+B1E;AAGD,eAAO,MAAM,0BAA0B,6DAmErC,CAAC;AAEH,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA6B9G;AA4CD,eAAO,MAAM,6BAA6B,4EAsKxC,CAAC;AAEH,eAAO,MAAM,8BAA8B,6EAkIzC,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/config.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,KAAK,eAAe,EAKrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,2BAA2B,EAIjC,MAAM,+CAA+C,CAAC;AAWvD,OAAO,EACL,KAAK,8BAA8B,EAEpC,MAAM,+CAA+C,CAAC;AAOvD,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AAEtG,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB,YAAY,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAGnD;CACF;AAGD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;AAE1E,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAY,GAAG,WAAW,CAOhE;AAKD,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAGD,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,MAAM,MAAM,8BAA8B,GAAG;IAC3C,EAAE,EAAE,eAAe,CAAC;IAEpB,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,2BAA2B,CAAC;CACtC,CAAC;AAsBF,eAAO,MAAM,uBAAuB,yEAoBlC,CAAC;AAGH,wBAAsB,eAAe,IAAI,OAAO,CAAC,8BAA8B,CAAC,CAiB/E;AAID,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,eAAe,CAAC,CAmC1E;AAGD,eAAO,MAAM,0BAA0B,6DAgGrC,CAAC;AAKH,wBAAsB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAWtH;AAED,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA6B9G;AAwED,eAAO,MAAM,6BAA6B,4EA8KxC,CAAC;AAEH,eAAO,MAAM,8BAA8B,6EA2GzC,CAAC"}
@@ -2,10 +2,16 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
+ import fs from 'node:fs';
5
6
  import path from 'node:path';
6
7
  import { pathToFileURL } from 'node:url';
7
8
  import globToRegExp from 'glob-to-regexp';
8
- import { isKvStoreConfigRc, isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
9
+ import { checkStaticPublisherWorkingDir, isKvStoreConfigRc, isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
10
+ import { MANAGED_APP_DIR, PROJECT_FILE_NAME, RC_FILE_NAME, } from '../../models/config/static-publish-project.js';
11
+ import { validateCollectionSelection } from '../../models/config/collection-selection.js';
12
+ import { checkTemplateSettings } from '../../models/config/template-settings.js';
13
+ import { APP_TEMPLATE_NAMES, isAppTemplateName } from '../commands/scaffold/app-template.js';
14
+ import { checkFastlyTomlSections } from '../commands/scaffold/fastly-toml-sections.js';
9
15
  import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
10
16
  import { getS3StorageConfigFromRc, } from '../../models/config/s3-storage-config.js';
11
17
  import { buildNormalizeFunctionForArray, buildNormalizeFunctionForObject, isSpecified, isStringAndNotEmpty, } from './data.js';
@@ -15,9 +21,91 @@ export class LoadConfigError extends Error {
15
21
  this.errors = errors;
16
22
  }
17
23
  }
24
+ export function detectProjectMode(dir = '.') {
25
+ const hasProject = fs.existsSync(path.resolve(dir, PROJECT_FILE_NAME));
26
+ const hasRc = fs.existsSync(path.resolve(dir, RC_FILE_NAME));
27
+ if (hasProject && hasRc) {
28
+ return 'conflict';
29
+ }
30
+ return hasProject ? 'managed' : hasRc ? 'ejected' : 'scaffold';
31
+ }
32
+ // The directory of the Compute app: the current directory in an ejected app,
33
+ // or .static-publish/app in a managed project. The local KV Store file has
34
+ // paths relative to it, because `fastly compute serve` runs there.
35
+ export function getComputeAppDir() {
36
+ return detectProjectMode() === 'managed' ? path.resolve(MANAGED_APP_DIR) : path.resolve();
37
+ }
38
+ // The name of the config file of the current directory, for messages.
39
+ export function configFileName() {
40
+ return detectProjectMode() === 'managed' ? PROJECT_FILE_NAME : RC_FILE_NAME;
41
+ }
42
+ async function importDefault(configFile) {
43
+ const configFilePath = path.resolve(configFile);
44
+ let configRaw;
45
+ try {
46
+ configRaw = (await import(pathToFileURL(configFilePath).href)).default;
47
+ }
48
+ catch (ex) {
49
+ throw new LoadConfigError(configFile, [
50
+ `Unable to load ${configFilePath}`,
51
+ String(ex),
52
+ ]);
53
+ }
54
+ if (configRaw == null) {
55
+ throw new LoadConfigError(configFile, [
56
+ `Unable to load ${configFilePath}`,
57
+ `default export does not exist or is null.`
58
+ ]);
59
+ }
60
+ return configRaw;
61
+ }
62
+ export const normalizeProjectManaged = buildNormalizeFunctionForObject((config, errors) => {
63
+ const { name, description, authors, template, serviceId, staticPublishVersion, fastlyToml } = config;
64
+ for (const [key, value] of Object.entries({ name, description, template, serviceId, staticPublishVersion })) {
65
+ if (value !== undefined && typeof value !== 'string') {
66
+ errors.push(`managed.${key}, if specified, must be a string.`);
67
+ }
68
+ }
69
+ if (authors !== undefined && !(Array.isArray(authors) && authors.every(x => typeof x === 'string'))) {
70
+ errors.push('managed.authors, if specified, must be an array of strings.');
71
+ }
72
+ if (typeof template === 'string' && !isAppTemplateName(template)) {
73
+ errors.push(`managed.template must be one of: ${APP_TEMPLATE_NAMES.join(', ')}.`);
74
+ }
75
+ if (fastlyToml !== undefined) {
76
+ checkFastlyTomlSections(fastlyToml, errors);
77
+ }
78
+ if (errors.length > 0) {
79
+ return null;
80
+ }
81
+ return { name, description, authors, template, serviceId, staticPublishVersion, fastlyToml };
82
+ });
83
+ // Loads static-publish.project.js from the current directory (the project dir).
84
+ export async function loadProjectFile() {
85
+ const configFile = `./${PROJECT_FILE_NAME}`;
86
+ const configRaw = await importDefault(configFile);
87
+ const errors = [];
88
+ const rc = normalizeStaticPublisherRc(configRaw, errors);
89
+ if (!('publishContent' in configRaw) || configRaw.publishContent == null || typeof configRaw.publishContent !== 'object') {
90
+ errors.push('publishContent must be specified.');
91
+ }
92
+ let managed = {};
93
+ if ('managed' in configRaw && configRaw.managed != null) {
94
+ managed = normalizeProjectManaged(configRaw.managed, errors);
95
+ }
96
+ if (rc == null || managed == null || errors.length > 0) {
97
+ throw new LoadConfigError(configFile, errors);
98
+ }
99
+ return { rc, publishContent: configRaw.publishContent, managed };
100
+ }
101
+ // Loads the settings of the app: static-publish.rc.js in an ejected app, or the
102
+ // top level of static-publish.project.js in a managed project.
18
103
  export async function loadStaticPublisherRcFile() {
104
+ if (detectProjectMode() === 'managed') {
105
+ return (await loadProjectFile()).rc;
106
+ }
19
107
  let configRaw;
20
- const configFile = './static-publish.rc.js';
108
+ const configFile = `./${RC_FILE_NAME}`;
21
109
  const configFilePath = path.resolve(configFile);
22
110
  try {
23
111
  configRaw = (await import(pathToFileURL(configFilePath).href)).default;
@@ -42,7 +130,7 @@ export async function loadStaticPublisherRcFile() {
42
130
  return config;
43
131
  }
44
132
  export const normalizeStaticPublisherRc = buildNormalizeFunctionForObject((config, errors) => {
45
- let { publishId, defaultCollectionName, staticPublisherWorkingDir, } = config;
133
+ let { publishId, defaultCollectionName, staticPublisherWorkingDir, generatedFrom, collectionSelection, build, templateOptions, } = config;
46
134
  let storage = null;
47
135
  if (isKvStoreConfigRc(config)) {
48
136
  storage = {
@@ -82,24 +170,60 @@ export const normalizeStaticPublisherRc = buildNormalizeFunctionForObject((confi
82
170
  errors.push('staticPublisherWorkingDir must be specified.');
83
171
  }
84
172
  else {
85
- if (staticPublisherWorkingDir.startsWith('./') &&
86
- staticPublisherWorkingDir !== './' &&
87
- !staticPublisherWorkingDir.includes('//')) {
88
- // ok
89
- }
90
- else {
91
- errors.push('staticPublisherWorkingDir must be a relative subdirectory.');
173
+ const workingDirError = checkStaticPublisherWorkingDir(staticPublisherWorkingDir);
174
+ if (workingDirError != null) {
175
+ // The caller uses the result even if there are errors. Thus return null,
176
+ // so that publish-content never writes into a directory that breaks the rule.
177
+ errors.push(workingDirError);
178
+ return null;
92
179
  }
93
180
  while (staticPublisherWorkingDir.endsWith('/')) {
94
181
  staticPublisherWorkingDir = staticPublisherWorkingDir.slice(0, -1);
95
182
  }
96
183
  }
184
+ if (isSpecified(config, 'collectionSelection') && collectionSelection != null) {
185
+ // The caller uses the result even if there are errors. Thus return null, so
186
+ // that a collectionSelection that is not valid stops the command.
187
+ const collectionSelectionErrors = validateCollectionSelection(collectionSelection);
188
+ if (collectionSelectionErrors.length > 0) {
189
+ errors.push(...collectionSelectionErrors);
190
+ return null;
191
+ }
192
+ }
193
+ else {
194
+ collectionSelection = undefined;
195
+ }
196
+ // The settings of the templates. A setting that no template declares is only
197
+ // a warning.
198
+ const templateSettings = checkTemplateSettings(build, templateOptions);
199
+ for (const warning of templateSettings.warnings) {
200
+ console.warn(`⚠️ ${warning}`);
201
+ }
202
+ if (templateSettings.errors.length > 0) {
203
+ errors.push(...templateSettings.errors);
204
+ return null;
205
+ }
97
206
  return Object.assign({}, storage, {
98
207
  publishId,
99
208
  defaultCollectionName,
100
209
  staticPublisherWorkingDir,
101
- });
210
+ }, generatedFrom != null ? { generatedFrom } : {}, collectionSelection != null ? { collectionSelection } : {}, build != null ? { build } : {}, templateOptions != null ? { templateOptions } : {});
102
211
  });
212
+ // Loads the publish settings: the file of --config if given, else the
213
+ // publishContent section of static-publish.project.js in a managed project,
214
+ // else ./publish-content.config.js.
215
+ export async function loadPublishContentConfig(configFile) {
216
+ if (configFile == null && detectProjectMode() === 'managed') {
217
+ const project = await loadProjectFile();
218
+ const errors = [];
219
+ const config = normalizePublishContentConfig(project.publishContent, errors);
220
+ if (config == null || errors.length > 0) {
221
+ throw new LoadConfigError(`./${PROJECT_FILE_NAME} (publishContent)`, errors);
222
+ }
223
+ return config;
224
+ }
225
+ return loadPublishContentConfigFile(configFile ?? './publish-content.config.js');
226
+ }
103
227
  export async function loadPublishContentConfigFile(configFile) {
104
228
  let configRaw;
105
229
  const configFilePath = path.resolve(configFile);
@@ -125,6 +249,34 @@ export async function loadPublishContentConfigFile(configFile) {
125
249
  }
126
250
  return config;
127
251
  }
252
+ // staticItems and hiddenItems: a string, an array of strings, false, or null.
253
+ // Glob patterns become 're:' items. See models/config/item-patterns.ts.
254
+ function normalizeItemList(name, value, errors) {
255
+ if (value === null || value === false) {
256
+ value = [];
257
+ }
258
+ if (!Array.isArray(value)) {
259
+ value = [value];
260
+ }
261
+ const items = value;
262
+ if (!items.every((x) => typeof x === 'string')) {
263
+ errors.push(`${name}, if specified, must be a string value, an array of string values, false, or null`);
264
+ return [];
265
+ }
266
+ return items.map((x, index) => {
267
+ if (x.includes('*')) {
268
+ try {
269
+ const regexp = globToRegExp(x, { globstar: true });
270
+ return 're:' + String(regexp);
271
+ }
272
+ catch {
273
+ errors.push(`${name} item at index ${index}, '${x}', cannot be parsed as a glob pattern.`);
274
+ return '';
275
+ }
276
+ }
277
+ return x;
278
+ });
279
+ }
128
280
  const normalizeContentTypeDef = buildNormalizeFunctionForObject((config, errors) => {
129
281
  let { test, contentType, text } = config;
130
282
  if (typeof test === 'function' || test instanceof RegExp) {
@@ -163,7 +315,7 @@ const normalizeContentTypeDefs = buildNormalizeFunctionForArray((config, errors)
163
315
  return normalizeContentTypeDef(config, errors);
164
316
  });
165
317
  export const normalizePublishContentConfig = buildNormalizeFunctionForObject((config, errors) => {
166
- let { rootDir, excludeDirs, excludeDotFiles, includeWellKnown, assetInclusionTest, kvStoreAssetInclusionTest, contentCompression, brotliQuality, contentTypes, server, } = config;
318
+ let { rootDir, excludeDirs, excludeDotFiles, includeWellKnown, assetInclusionTest, kvStoreAssetInclusionTest, hiddenItems, contentCompression, brotliQuality, contentTypes, server, } = config;
167
319
  if (!isSpecified(config, 'rootDir')) {
168
320
  errors.push('rootDir must be specified.');
169
321
  }
@@ -255,6 +407,12 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
255
407
  else {
256
408
  errors.push('assetInclusionTest, if specified, must be null or a function.');
257
409
  }
410
+ if (!isSpecified(config, 'hiddenItems')) {
411
+ hiddenItems = [];
412
+ }
413
+ else {
414
+ hiddenItems = normalizeItemList('hiddenItems', hiddenItems, errors);
415
+ }
258
416
  if (!isSpecified(config, 'contentCompression')) {
259
417
  contentCompression = ['br', 'gzip'];
260
418
  }
@@ -320,6 +478,7 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
320
478
  excludeDotFiles,
321
479
  includeWellKnown,
322
480
  assetInclusionTest,
481
+ hiddenItems,
323
482
  contentCompression,
324
483
  brotliQuality,
325
484
  contentTypes,
@@ -343,32 +502,7 @@ export const normalizePublisherServerConfig = buildNormalizeFunctionForObject((c
343
502
  staticItems = [];
344
503
  }
345
504
  else {
346
- if (staticItems === null || staticItems === false) {
347
- staticItems = [];
348
- }
349
- if (!Array.isArray(staticItems)) {
350
- staticItems = [staticItems];
351
- }
352
- if (staticItems.every((x) => typeof x === 'string')) {
353
- staticItems = staticItems.map((x, index) => {
354
- if (x.includes('*')) {
355
- let re;
356
- try {
357
- const regexp = globToRegExp(x, { globstar: true });
358
- re = 're:' + String(regexp);
359
- }
360
- catch {
361
- errors.push(`staticItems item at index ${index}, '${x}', cannot be parsed as glob pattern.`);
362
- re = null;
363
- }
364
- return re;
365
- }
366
- return x;
367
- });
368
- }
369
- else {
370
- errors.push('staticItems, if specified, must be a string value, an array of string values, false, or null');
371
- }
505
+ staticItems = normalizeItemList('staticItems', staticItems, errors);
372
506
  }
373
507
  if (!isSpecified(config, 'allowedEncodings')) {
374
508
  allowedEncodings = ['br', 'gzip'];
@@ -1 +1 @@
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
+ {"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,SAE1E,OAAO,WAAU,MAAM,EAAE,KAAQ,OAAO,GAAG,IAAI,CAmB7D;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,SAEvE,OAAO,WAAU,MAAM,EAAE,KAAQ,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"}
@@ -0,0 +1,13 @@
1
+ export type GlobalOptions = {
2
+ projectDir: string | undefined;
3
+ version: boolean;
4
+ nonInteractive: boolean;
5
+ json: boolean;
6
+ secrets: string[];
7
+ argv: string[];
8
+ };
9
+ export declare function isCiEnvironment(env: Record<string, string | undefined>): boolean;
10
+ export declare function parseGlobalOptions(args: string[], env?: Record<string, string | undefined>): GlobalOptions | {
11
+ error: string;
12
+ };
13
+ //# sourceMappingURL=global-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-options.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/global-options.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG;IAG1B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/B,OAAO,EAAE,OAAO,CAAC;IAEjB,cAAc,EAAE,OAAO,CAAC;IAExB,IAAI,EAAE,OAAO,CAAC;IAGd,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAOF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,WAEtE;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAM,GAAG,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAsClI"}