@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
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ // The options of the commands that take a secret.
6
+ const SECRET_OPTIONS = ['--fastly-api-token', '--s3-secret-access-key'];
7
+ // CI is set (to a value that is not empty, 'false', or '0') by CI systems such
8
+ // as GitHub Actions.
9
+ export function isCiEnvironment(env) {
10
+ return env.CI != null && env.CI !== '' && env.CI !== 'false' && env.CI !== '0';
11
+ }
12
+ export function parseGlobalOptions(args, env = {}) {
13
+ let projectDir;
14
+ let version = false;
15
+ let nonInteractive = isCiEnvironment(env);
16
+ let json = false;
17
+ const secrets = [];
18
+ const argv = [];
19
+ for (let i = 0; i < args.length; i++) {
20
+ const arg = args[i];
21
+ for (const option of SECRET_OPTIONS) {
22
+ if (arg.startsWith(`${option}=`)) {
23
+ secrets.push(arg.slice(option.length + 1));
24
+ }
25
+ else if (arg === option && args[i + 1] != null) {
26
+ secrets.push(args[i + 1]);
27
+ }
28
+ }
29
+ if (arg === '--version') {
30
+ version = true;
31
+ }
32
+ else if (arg === '--non-interactive') {
33
+ nonInteractive = true;
34
+ }
35
+ else if (arg === '--json') {
36
+ json = true;
37
+ }
38
+ else if (arg === '--project-dir' || arg.startsWith('--project-dir=')) {
39
+ const value = arg === '--project-dir' ? args[++i] : arg.slice('--project-dir='.length);
40
+ if (value == null || value === '' || value.startsWith('--')) {
41
+ return { error: '--project-dir needs a directory.' };
42
+ }
43
+ if (projectDir != null) {
44
+ return { error: '--project-dir can be given only one time.' };
45
+ }
46
+ projectDir = value;
47
+ }
48
+ else {
49
+ argv.push(arg);
50
+ }
51
+ }
52
+ return { projectDir, version, nonInteractive, json, secrets, argv };
53
+ }
@@ -1,5 +1,6 @@
1
1
  import { StorageProviderBatchEntry } from '../storage/storage-provider.js';
2
2
  export declare const KV_STORE_CHUNK_SIZE: number;
3
+ export declare function chunkSizes(size: number, chunkSize: number): number[];
3
4
  export declare function shouldRecreateChunks(chunksDir: string, numChunks: number, item: StorageProviderBatchEntry, chunkSize: number): boolean;
4
5
  export declare function applyKVStoreEntriesChunks(kvStoreItemDescriptions: StorageProviderBatchEntry[], chunkSize: number): Promise<void>;
5
6
  export declare const KV_BATCH_MAX_ITEMS = 256;
@@ -1 +1 @@
1
- {"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,eAAO,MAAM,mBAAmB,QAAqB,CAAC;AAEtD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,EAAE,SAAS,EAAE,MAAM,WAkC5H;AAED,wBAAsB,yBAAyB,CAAC,uBAAuB,EAAE,yBAAyB,EAAE,EAAE,SAAS,EAAE,MAAM,iBAoGtH;AAED,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,kBAAkB,QAAoB,CAAC;AAEpD,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,yBAAyB,EAAE,CAAC;CACtC,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,yBAAyB,EAAE,EACpC,QAAQ,GAAE,MAA2B,EACrC,QAAQ,GAAE,MAA2B,GACpC;IAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAAC,SAAS,EAAE,yBAAyB,EAAE,CAAA;CAAE,CAuCpE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,yBAAyB,GAAG,MAAM,CAOhF;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,yBAAyB,EAAE,EACpC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,GACxB,yBAAyB,EAAE,CAE7B"}
1
+ {"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,eAAO,MAAM,mBAAmB,QAAqB,CAAC;AAItD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAGpE;AAED,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,EAAE,SAAS,EAAE,MAAM,WAkC5H;AAED,wBAAsB,yBAAyB,CAAC,uBAAuB,EAAE,yBAAyB,EAAE,EAAE,SAAS,EAAE,MAAM,iBAiEtH;AAED,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,kBAAkB,QAAoB,CAAC;AAEpD,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,yBAAyB,EAAE,CAAC;CACtC,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,yBAAyB,EAAE,EACpC,QAAQ,GAAE,MAA2B,EACrC,QAAQ,GAAE,MAA2B,GACpC;IAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAAC,SAAS,EAAE,yBAAyB,EAAE,CAAA;CAAE,CAuCpE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,yBAAyB,GAAG,MAAM,CAOhF;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,yBAAyB,EAAE,EACpC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,GACxB,yBAAyB,EAAE,CAE7B"}
@@ -3,9 +3,16 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import fs from 'node:fs';
6
+ import { pipeline } from 'node:stream/promises';
6
7
  import { directoryExists, getFileSize } from './files.js';
7
8
  // split large files into 20MiB chunks
8
9
  export const KV_STORE_CHUNK_SIZE = 1_024 * 1_024 * 20;
10
+ // The size of each chunk of a file of `size` bytes. All chunks have chunkSize
11
+ // bytes, except the last, which has the bytes that are left.
12
+ export function chunkSizes(size, chunkSize) {
13
+ const numChunks = Math.ceil(size / chunkSize);
14
+ return Array.from({ length: numChunks }, (_, chunk) => Math.min(chunkSize, size - chunk * chunkSize));
15
+ }
9
16
  export function shouldRecreateChunks(chunksDir, numChunks, item, chunkSize) {
10
17
  console.log(` 📄 '${item.key}' - ${item.size} bytes → ${numChunks} chunks`);
11
18
  if (!directoryExists(chunksDir)) {
@@ -17,7 +24,7 @@ export function shouldRecreateChunks(chunksDir, numChunks, item, chunkSize) {
17
24
  console.log(` ・ Recreating chunks for '${item.key}' - found ${existingChunks} existing chunk(s), expected ${numChunks}`);
18
25
  return true;
19
26
  }
20
- const finalChunkSize = item.size % chunkSize;
27
+ const expectedFileSizes = chunkSizes(item.size, chunkSize);
21
28
  for (let chunk = 0; chunk < numChunks; chunk++) {
22
29
  const chunkFileName = `${chunksDir}/${chunk}`;
23
30
  // If the chunk does not exist
@@ -26,7 +33,7 @@ export function shouldRecreateChunks(chunksDir, numChunks, item, chunkSize) {
26
33
  return true;
27
34
  }
28
35
  // or if the chunk isn't the expected size
29
- const expectedFileSize = chunk === numChunks - 1 ? finalChunkSize : chunkSize;
36
+ const expectedFileSize = expectedFileSizes[chunk];
30
37
  const existingFileSize = getFileSize(chunkFileName);
31
38
  if (existingFileSize !== expectedFileSize) {
32
39
  console.log(` ・ Recreating chunks for '${item.key}' - chunk ${chunk} existing file size ${existingFileSize} does not match expected size ${expectedFileSize}`);
@@ -52,44 +59,13 @@ export async function applyKVStoreEntriesChunks(kvStoreItemDescriptions, chunkSi
52
59
  // Recreate chunks
53
60
  fs.rmSync(chunksDir, { recursive: true, force: true });
54
61
  fs.mkdirSync(chunksDir, { recursive: true });
55
- const numWrittenChunks = await new Promise((resolve, reject) => {
56
- const chunkPaths = [];
57
- let chunkIndex = 0;
58
- let bytesWritten = 0;
59
- let currentStream = null;
60
- const inputStream = fs.createReadStream(item.filePath);
61
- inputStream.on('error', reject);
62
- inputStream.on('data', (chunk) => {
63
- let offset = 0;
64
- while (offset < chunk.length) {
65
- if (!currentStream || bytesWritten >= chunkSize) {
66
- if (currentStream != null) {
67
- currentStream.end();
68
- }
69
- const chunkFileName = `${chunksDir}/${chunkIndex}`;
70
- currentStream = fs.createWriteStream(chunkFileName);
71
- chunkPaths.push(chunkFileName);
72
- chunkIndex++;
73
- bytesWritten = 0;
74
- }
75
- const bytesLeftInChunk = chunkSize - bytesWritten;
76
- const bytesLeftInBuffer = chunk.length - offset;
77
- const bytesToWrite = Math.min(bytesLeftInChunk, bytesLeftInBuffer);
78
- const slice = chunk.slice(offset, offset + bytesToWrite);
79
- currentStream.write(slice);
80
- bytesWritten += bytesToWrite;
81
- offset += bytesToWrite;
82
- }
83
- });
84
- inputStream.on('end', () => {
85
- if (currentStream != null) {
86
- currentStream.end();
87
- }
88
- resolve(chunkPaths.length);
89
- });
90
- });
91
- if (numWrittenChunks !== numChunks) {
92
- throw new Error(`numWrittenChunks (${numWrittenChunks}) does not equal numChunks (${numChunks})`);
62
+ // Each chunk is a copy of a range of the file. pipeline() resolves
63
+ // after the chunk file is completely written, so the upload reads the
64
+ // full chunk.
65
+ let start = 0;
66
+ for (const [chunkIndex, size] of chunkSizes(item.size, chunkSize).entries()) {
67
+ await pipeline(fs.createReadStream(item.filePath, { start, end: start + size - 1 }), fs.createWriteStream(`${chunksDir}/${chunkIndex}`));
68
+ start += size;
93
69
  }
94
70
  }
95
71
  for (let chunkIndex = 0; chunkIndex < numChunks; chunkIndex++) {
@@ -1,7 +1,7 @@
1
1
  import { type StorageProviderBatchEntry } from '../storage/storage-provider.js';
2
2
  import { type KvStoreEntryInfo } from './kv-store.js';
3
3
  export declare function getLocalKVStoreKeys(storeFile: string, prefix?: string): Promise<string[]>;
4
- export declare function getLocalKvStoreEntry(storeFile: string, key: string, metadataOnly?: boolean): Promise<KvStoreEntryInfo | null>;
4
+ export declare function getLocalKvStoreEntry(storeFile: string, key: string, metadataOnly?: boolean, computeAppDir?: string): Promise<KvStoreEntryInfo | null>;
5
5
  export declare function localKvStoreSubmitEntry(storeFile: string, key: string, file: string, metadata: string | undefined): Promise<void>;
6
6
  export declare function localKvStoreDeleteEntry(storeFile: string, key: string): Promise<void>;
7
7
  export declare function writeKVStoreEntriesForLocal(storeFile: string, computeAppDir: string, kvStoreItemDescriptions: StorageProviderBatchEntry[]): void;
@@ -1 +1 @@
1
- {"version":3,"file":"kv-store-local-server.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-local-server.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAKtD,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,qBAoBhB;AAED,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,OAAO,GACrB,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA+BlC;AAED,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GAAG,SAAS,iBAmB7B;AAED,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,iBAgBZ;AAED,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,uBAAuB,EAAE,yBAAyB,EAAE,QAiCrD"}
1
+ {"version":3,"file":"kv-store-local-server.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-local-server.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAKtD,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,qBAoBhB;AAED,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,OAAO,EAEtB,aAAa,GAAE,MAAY,GAC1B,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA+BlC;AAED,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GAAG,SAAS,iBAmB7B;AAED,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,iBAgBZ;AAED,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,uBAAuB,EAAE,yBAAyB,EAAE,QAiCrD"}
@@ -20,7 +20,9 @@ export async function getLocalKVStoreKeys(storeFile, prefix) {
20
20
  }
21
21
  return keys;
22
22
  }
23
- export async function getLocalKvStoreEntry(storeFile, key, metadataOnly) {
23
+ export async function getLocalKvStoreEntry(storeFile, key, metadataOnly,
24
+ // The paths of the entries are relative to the Compute app dir.
25
+ computeAppDir = '.') {
24
26
  let store;
25
27
  try {
26
28
  // If the local KV store file exists, we have to add to it.
@@ -42,7 +44,7 @@ export async function getLocalKvStoreEntry(storeFile, key, metadataOnly) {
42
44
  response = new Response(obj.data);
43
45
  }
44
46
  else {
45
- const fileData = fs.readFileSync(obj.file);
47
+ const fileData = fs.readFileSync(path.resolve(computeAppDir, obj.file));
46
48
  response = new Response(fileData);
47
49
  }
48
50
  return {
@@ -0,0 +1,31 @@
1
+ export declare const EXIT_SUCCESS = 0;
2
+ export declare const EXIT_FAILED = 1;
3
+ export declare const EXIT_USAGE = 2;
4
+ export declare const JSON_SCHEMA_VERSION = 1;
5
+ declare const FAILED_CODES: readonly ['deploy-failed', 'failed'];
6
+ declare const USAGE_CODES: readonly ['usage', 'config-invalid', 'collection-name-invalid', 'collection-not-found', 'project-dir-not-found', 'json-not-supported', 'credentials-missing', 'version-mismatch', 'first-deploy-manual', 'version-not-published', 'template-init-needed'];
7
+ export type CliErrorCode = typeof FAILED_CODES[number] | typeof USAGE_CODES[number];
8
+ export declare const CLI_ERROR_CODES: readonly CliErrorCode[];
9
+ export type CliError = {
10
+ code: CliErrorCode;
11
+ message: string;
12
+ };
13
+ export declare class ConfigError extends Error {
14
+ }
15
+ export declare function exitCodeOf(code: CliErrorCode): 1 | 2;
16
+ export declare function isNonInteractive(): boolean;
17
+ export declare function isJsonMode(): boolean;
18
+ export declare function addSecret(value: string | undefined | null): void;
19
+ export declare function redactSecrets(text: string): string;
20
+ export declare function setUpOutput(options: {
21
+ nonInteractive: boolean;
22
+ json: boolean;
23
+ secrets: string[];
24
+ }, env: Record<string, string | undefined>): void;
25
+ export declare function recordFailure(code: CliErrorCode, message: string): void;
26
+ export declare function fail(code: CliErrorCode, message: string): void;
27
+ export declare function errorCodeOf(err: unknown): CliErrorCode;
28
+ export declare function setJsonResult(result: Record<string, unknown>): void;
29
+ export declare function writeJsonOutput(): void;
30
+ export {};
31
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/output.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,UAAU,IAAI,CAAC;AAE5B,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAGrC,QAAA,MAAM,YAAY,YAChB,eAAe,EACf,QAAQ,CACA,CAAC;AAGX,QAAA,MAAM,WAAW,YACf,OAAO,EACP,gBAAgB,EAChB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,CACd,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,MAAM,CAAC,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAEpF,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAAwC,CAAC;AAE5F,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAK/D,qBAAa,WAAY,SAAQ,KAAK;CAAG;AAEzC,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,SAE5C;AASD,wBAAgB,gBAAgB,YAE/B;AAGD,wBAAgB,UAAU,YAEzB;AAKD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,QAKzD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMlD;AAOD,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAE,cAAc,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,QAe1I;AAKD,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,QAGhE;AAGD,wBAAgB,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,QAGvD;AAID,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAStD;AAGD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAE5D;AAGD,wBAAgB,eAAe,SAa9B"}
@@ -0,0 +1,139 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import util from 'node:util';
6
+ // The contract with tools that run the CLI, for example in CI:
7
+ // - Exit codes: 0 success (also "nothing to do"), 1 the operation failed and a
8
+ // retry can help, 2 a usage or config error (a retry cannot help).
9
+ // - --json: stdout has exactly one JSON object, written at the end. The log
10
+ // lines go to stderr. Each object has schemaVersion. Adding a field keeps the
11
+ // version. Removing or changing a field increases it, only in a major release.
12
+ // - An error with --json: { schemaVersion, error: { code, message } }. The
13
+ // codes are part of the contract (CliErrorCode, also in the README). The
14
+ // message is for people, and can change.
15
+ export const EXIT_SUCCESS = 0;
16
+ export const EXIT_FAILED = 1;
17
+ export const EXIT_USAGE = 2;
18
+ export const JSON_SCHEMA_VERSION = 1;
19
+ // The codes that give exit 1.
20
+ const FAILED_CODES = [
21
+ 'deploy-failed', // the build or the deploy of the app failed
22
+ 'failed', // the operation failed, for example storage cannot be reached
23
+ ];
24
+ // The codes that give exit 2.
25
+ const USAGE_CODES = [
26
+ 'usage', // an unknown command or option, or a missing or incorrect option value
27
+ 'config-invalid', // a config file cannot be loaded or is not valid
28
+ 'collection-name-invalid', // a collection name breaks the rule
29
+ 'collection-not-found', // the command needs a collection that does not exist
30
+ 'project-dir-not-found', // --project-dir is not a directory, or has no config file
31
+ 'json-not-supported', // --json with a command that does not support it
32
+ 'credentials-missing', // a token or credentials are necessary, but not given
33
+ 'version-mismatch', // managed.staticPublishVersion is not the version that runs
34
+ 'first-deploy-manual', // a first deploy that must be done by hand (S3 storage, non-interactive)
35
+ 'version-not-published', // eject needs a version of this package that is on npm
36
+ 'template-init-needed', // template init --check: the template's folder is out of date
37
+ ];
38
+ export const CLI_ERROR_CODES = [...USAGE_CODES, ...FAILED_CODES];
39
+ // An error in the settings that a command finds after it loads them, for
40
+ // example a name in managed.fastlyToml that the CLI writes. The CLI gives the
41
+ // code config-invalid (exit 2) for it.
42
+ export class ConfigError extends Error {
43
+ }
44
+ export function exitCodeOf(code) {
45
+ return FAILED_CODES.includes(code) ? EXIT_FAILED : EXIT_USAGE;
46
+ }
47
+ let nonInteractive = false;
48
+ let json = false;
49
+ let jsonResult = null;
50
+ let recordedError = null;
51
+ // True with --non-interactive, or when the CI environment variable is set. Then
52
+ // a command never asks a question: missing input is an error.
53
+ export function isNonInteractive() {
54
+ return nonInteractive;
55
+ }
56
+ // True with --json.
57
+ export function isJsonMode() {
58
+ return json;
59
+ }
60
+ // Values that must never appear in the output, for example the API token.
61
+ const secrets = new Set();
62
+ export function addSecret(value) {
63
+ // A very short value would also replace normal text.
64
+ if (value != null && value.length >= 8) {
65
+ secrets.add(value);
66
+ }
67
+ }
68
+ export function redactSecrets(text) {
69
+ let result = text;
70
+ for (const secret of secrets) {
71
+ result = result.split(secret).join('[REDACTED]');
72
+ }
73
+ return result;
74
+ }
75
+ // Sets the mode of the run, and replaces the console methods with ones that
76
+ // redact the secrets: the given values, and the values of FASTLY_API_TOKEN and
77
+ // S3_SECRET_ACCESS_KEY. Thus an error message can never show a secret. With
78
+ // --json, all console methods write to stderr, so that stdout has only the
79
+ // JSON object.
80
+ export function setUpOutput(options, env) {
81
+ nonInteractive = options.nonInteractive;
82
+ json = options.json;
83
+ for (const secret of options.secrets) {
84
+ addSecret(secret);
85
+ }
86
+ addSecret(env.FASTLY_API_TOKEN);
87
+ addSecret(env.S3_SECRET_ACCESS_KEY);
88
+ for (const method of ['log', 'info', 'debug', 'warn', 'error']) {
89
+ const stream = json || method === 'warn' || method === 'error' ? process.stderr : process.stdout;
90
+ console[method] = (...args) => {
91
+ stream.write(redactSecrets(util.format(...args)) + '\n');
92
+ };
93
+ }
94
+ }
95
+ // Make the command fail with the exit code of the error code. Use this when
96
+ // the log already shows the error for the customer. With --json, the output
97
+ // has the first error only.
98
+ export function recordFailure(code, message) {
99
+ recordedError ??= { code, message: redactSecrets(message.replace(/^(Error: )?❌\s*/, '')) };
100
+ process.exitCode = exitCodeOf(code);
101
+ }
102
+ // Show an error for the customer, and make the command fail.
103
+ export function fail(code, message) {
104
+ console.error(`❌ ${message}`);
105
+ recordFailure(code, message);
106
+ }
107
+ // The error code for an error that a storage provider or the purge setup
108
+ // throws before the operation starts.
109
+ export function errorCodeOf(err) {
110
+ const message = String(err instanceof Error ? err.message : err);
111
+ if (/not provided/i.test(message)) {
112
+ return 'credentials-missing';
113
+ }
114
+ if (/^(❌ )?Unknown --|^--local is available only/.test(message)) {
115
+ return 'usage';
116
+ }
117
+ return 'config-invalid';
118
+ }
119
+ // The result of the command, for --json.
120
+ export function setJsonResult(result) {
121
+ jsonResult = result;
122
+ }
123
+ // With --json, write the one JSON object to stdout: the error, or the result.
124
+ export function writeJsonOutput() {
125
+ if (!json) {
126
+ return;
127
+ }
128
+ let output;
129
+ if (recordedError != null) {
130
+ output = { schemaVersion: JSON_SCHEMA_VERSION, error: recordedError };
131
+ }
132
+ else if (process.exitCode != null && process.exitCode !== EXIT_SUCCESS) {
133
+ output = { schemaVersion: JSON_SCHEMA_VERSION, error: { code: 'failed', message: 'The command failed.' } };
134
+ }
135
+ else {
136
+ output = { schemaVersion: JSON_SCHEMA_VERSION, ...jsonResult };
137
+ }
138
+ process.stdout.write(redactSecrets(JSON.stringify(output, undefined, 2)) + '\n');
139
+ }
@@ -5,5 +5,8 @@ export type PackageJson = {
5
5
  dependencies?: Record<string, string>;
6
6
  devDependencies?: Record<string, string>;
7
7
  };
8
+ export declare function getOwnPackageDir(): string;
9
+ export declare function readOwnPackageJson(): Record<string, any>;
10
+ export declare function getOwnVersion(): string;
8
11
  export declare function findComputeJsStaticPublisherVersion(packageJson: PackageJson | null): string;
9
12
  //# sourceMappingURL=package.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/package.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,wBAAgB,mCAAmC,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,UA8ClF"}
1
+ {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/package.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAGF,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAGD,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAExD;AAGD,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,mCAAmC,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,UA8ClF"}
@@ -4,6 +4,18 @@
4
4
  */
5
5
  import fs from 'node:fs';
6
6
  import path from 'node:path';
7
+ // The package dir of the copy of this package that runs.
8
+ export function getOwnPackageDir() {
9
+ return path.resolve(import.meta.dirname, '../../../..');
10
+ }
11
+ // The package.json of the copy of this package that runs.
12
+ export function readOwnPackageJson() {
13
+ return JSON.parse(fs.readFileSync(path.resolve(getOwnPackageDir(), 'package.json'), 'utf-8'));
14
+ }
15
+ // The version of this package, from the package.json of the copy that runs.
16
+ export function getOwnVersion() {
17
+ return readOwnPackageJson().version;
18
+ }
7
19
  export function findComputeJsStaticPublisherVersion(packageJson) {
8
20
  // Get the current compute js static publisher version.
9
21
  let computeJsStaticPublisherVersion = null;
@@ -0,0 +1,11 @@
1
+ export declare const PROGRESS_INTERVAL = 1000;
2
+ export declare class ProgressLog {
3
+ private readonly label;
4
+ private readonly verbose;
5
+ private readonly total?;
6
+ private done;
7
+ private nextReport;
8
+ constructor(label: string, verbose: boolean, total?: number | undefined);
9
+ add(count: number, message: () => string): void;
10
+ }
11
+ //# sourceMappingURL=progress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/progress.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAKtC,qBAAa,WAAW;IAKpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;IANzB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,UAAU,CAAqB;IAEvC,YACmB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,MAAM,YAAA,EAC7B;IAGJ,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,MAAM,QAavC;CACF"}
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ export const PROGRESS_INTERVAL = 1000;
6
+ // Logs the progress of a loop over many items. With verbose, it logs a line
7
+ // for each call. Else, it logs one line each time the count passes another
8
+ // PROGRESS_INTERVAL items, so that a large site does not make a large log.
9
+ export class ProgressLog {
10
+ constructor(label, verbose, total) {
11
+ this.label = label;
12
+ this.verbose = verbose;
13
+ this.total = total;
14
+ this.done = 0;
15
+ this.nextReport = PROGRESS_INTERVAL;
16
+ }
17
+ // Records count items. The message is made only if it is logged.
18
+ add(count, message) {
19
+ this.done += count;
20
+ if (this.verbose) {
21
+ console.log(message());
22
+ return;
23
+ }
24
+ if (this.done < this.nextReport || (this.total != null && this.done >= this.total)) {
25
+ return;
26
+ }
27
+ console.log(` | ${this.label}: ${this.done}${this.total != null ? ` of ${this.total}` : ''}`);
28
+ while (this.nextReport <= this.done) {
29
+ this.nextReport += PROGRESS_INTERVAL;
30
+ }
31
+ }
32
+ }
@@ -1,5 +1,5 @@
1
1
  import { type FastlyApiContext } from './api-token.js';
2
- export declare const purgeEnvironments: readonly ["production", "staging"];
2
+ export declare const purgeEnvironments: readonly ['production', 'staging'];
3
3
  export type PurgeEnvironment = typeof purgeEnvironments[number];
4
4
  export declare function parsePurgeEnvironments(values: unknown): PurgeEnvironment[];
5
5
  export type PurgeTarget = {
@@ -11,10 +11,22 @@ export type LoadPurgeTargetParams = {
11
11
  localMode: boolean;
12
12
  computeAppDir: string;
13
13
  fastlyServiceId: unknown;
14
+ projectServiceId?: string;
14
15
  fastlyApiToken: unknown;
15
16
  purgeEnvironments: unknown;
16
17
  };
17
18
  export declare function loadPurgeTarget(params: LoadPurgeTargetParams): PurgeTarget | null;
18
- export declare function purgeSurrogateKey(fastlyApiContext: FastlyApiContext, fastlyServiceId: string, surrogateKey: string, softPurge?: boolean, environment?: PurgeEnvironment): Promise<boolean>;
19
- export declare function purgeCollection(purgeTarget: PurgeTarget, publishId: string, collectionName: string): Promise<void>;
19
+ export type PurgeOutcome = {
20
+ result: 'purged';
21
+ } | {
22
+ result: 'not-staged';
23
+ } | {
24
+ result: 'failed';
25
+ reason: string;
26
+ };
27
+ export declare function purgeSurrogateKey(fastlyApiContext: FastlyApiContext, fastlyServiceId: string, surrogateKey: string, softPurge?: boolean, environment?: PurgeEnvironment): Promise<PurgeOutcome>;
28
+ export type PurgeResult = {
29
+ environment: PurgeEnvironment;
30
+ } & PurgeOutcome;
31
+ export declare function purgeCollection(purgeTarget: PurgeTarget, publishId: string, collectionName: string): Promise<PurgeResult[]>;
20
32
  //# sourceMappingURL=purge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"purge.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/purge.ts"],"names":[],"mappings":"AAOA,OAAO,EAAiB,KAAK,gBAAgB,EAA4B,MAAM,gBAAgB,CAAC;AAGhG,eAAO,MAAM,iBAAiB,oCAAuC,CAAC;AACtE,MAAM,MAAM,gBAAgB,GAAG,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAIhE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAkB1E;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,YAAY,EAAE,gBAAgB,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAMF,wBAAgB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,WAAW,GAAG,IAAI,CAgCjF;AAED,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,gBAAgB,EAClC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,GAAE,OAAe,EAC1B,WAAW,GAAE,gBAA+B,oBA4B7C;AAID,wBAAsB,eAAe,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iBAWxG"}
1
+ {"version":3,"file":"purge.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/purge.ts"],"names":[],"mappings":"AAOA,OAAO,EAAiB,KAAK,gBAAgB,EAA4B,MAAM,gBAAgB,CAAC;AAGhG,eAAO,MAAM,iBAAiB,YAAK,YAAY,EAAE,SAAS,CAAW,CAAC;AACtE,MAAM,MAAM,gBAAgB,GAAG,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAIhE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAkB1E;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,YAAY,EAAE,gBAAgB,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;IAEzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,OAAO,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAMF,wBAAgB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,WAAW,GAAG,IAAI,CAiCjF;AAMD,MAAM,MAAM,YAAY,GACpB;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GACpB;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GACxB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzC,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,gBAAgB,EAClC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,GAAE,OAAe,EAC1B,WAAW,GAAE,gBAA+B,GAC3C,OAAO,CAAC,YAAY,CAAC,CA8BvB;AAED,MAAM,MAAM,WAAW,GAAG;IAAE,WAAW,EAAE,gBAAgB,CAAA;CAAE,GAAG,YAAY,CAAC;AAK3E,wBAAsB,eAAe,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAoBjI"}
@@ -41,9 +41,10 @@ export function loadPurgeTarget(params) {
41
41
  const serviceIdResult = loadServiceId({
42
42
  commandLine: params.fastlyServiceId,
43
43
  fastlyTomlPath: path.resolve(params.computeAppDir, 'fastly.toml'),
44
+ projectServiceId: params.projectServiceId,
44
45
  });
45
46
  if (serviceIdResult == null) {
46
- console.log(`- Service ID not found (--fastly-service-id, FASTLY_SERVICE_ID, or fastly.toml). Will skip the purge.`);
47
+ console.log(`- Service ID not found (--fastly-service-id, FASTLY_SERVICE_ID, managed.serviceId, or fastly.toml). Will skip the purge.`);
47
48
  return null;
48
49
  }
49
50
  console.log(`✔️ Service ID from ${serviceIdResult.source}: ${serviceIdResult.serviceId}`);
@@ -75,24 +76,36 @@ export async function purgeSurrogateKey(fastlyApiContext, fastlyServiceId, surro
75
76
  }
76
77
  catch (err) {
77
78
  if (err instanceof FetchError) {
78
- return false;
79
+ if (environment === 'staging' && err.status === 404) {
80
+ return { result: 'not-staged' };
81
+ }
82
+ return { result: 'failed', reason: `${err.status}${err.detail != null ? ` ${err.detail}` : ''}` };
79
83
  }
80
84
  throw err;
81
85
  }
82
- return true;
86
+ return { result: 'purged' };
83
87
  }
84
88
  // Purges the cached responses of a collection in each environment of the purge
85
- // target. A failed purge is a warning, because the change to storage is done.
89
+ // target, and returns the outcome for each environment. A failed purge is a
90
+ // warning, because the change to storage is done.
86
91
  export async function purgeCollection(purgeTarget, publishId, collectionName) {
87
92
  const surrogateKey = `${publishId}-${collectionName}`;
93
+ const results = [];
88
94
  for (const environment of purgeTarget.environments) {
89
95
  console.log(`Purging surrogate key [${surrogateKey}] on service [${purgeTarget.serviceId}] (${environment})...`);
90
- const purged = await purgeSurrogateKey(purgeTarget.fastlyApiContext, purgeTarget.serviceId, surrogateKey, true, environment);
91
- if (purged) {
92
- console.log('Purged');
93
- }
94
- else {
95
- console.warn(`⚠️ Warning: Failed purging (${environment}). Cached copies may be served until they expire.`);
96
+ const outcome = await purgeSurrogateKey(purgeTarget.fastlyApiContext, purgeTarget.serviceId, surrogateKey, true, environment);
97
+ results.push({ environment, ...outcome });
98
+ switch (outcome.result) {
99
+ case 'purged':
100
+ console.log('Purged');
101
+ break;
102
+ case 'not-staged':
103
+ console.log(`Nothing purged (${environment}): the service has no staged version, or the service ID is not correct.`);
104
+ break;
105
+ case 'failed':
106
+ console.warn(`⚠️ Warning: Failed purging (${environment}): ${outcome.reason}. Cached copies may be served until they expire.`);
107
+ break;
96
108
  }
97
109
  }
110
+ return results;
98
111
  }
@@ -0,0 +1,2 @@
1
+ export declare const resourcesDir: string;
2
+ //# sourceMappingURL=resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/resources.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,YAAY,QAA6D,CAAC"}
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import path from 'node:path';
6
+ // The resources/ directory of this package. This file is
7
+ // build/cli/cli/util/resources.js in the package.
8
+ export const resourcesDir = path.resolve(import.meta.dirname, '../../../../resources');
@@ -5,6 +5,7 @@ export type LoadServiceIdResult = {
5
5
  export type LoadServiceIdParams = {
6
6
  commandLine: unknown;
7
7
  fastlyTomlPath: string;
8
+ projectServiceId?: string;
8
9
  };
9
10
  export declare function loadServiceId(params: LoadServiceIdParams): LoadServiceIdResult | null;
10
11
  //# sourceMappingURL=service-id.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"service-id.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/service-id.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAOF,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,GAAG,IAAI,CAmBrF"}
1
+ {"version":3,"file":"service-id.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/service-id.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IAEvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAQF,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,GAAG,IAAI,CAuBrF"}
@@ -7,7 +7,8 @@ import { readServiceId } from './fastly-toml.js';
7
7
  // Finds the Fastly Service ID to purge after a change to a collection. Checks, in order:
8
8
  // 1. The command line (--fastly-service-id)
9
9
  // 2. The FASTLY_SERVICE_ID environment variable
10
- // 3. service_id in fastly.toml
10
+ // 3. managed.serviceId in static-publish.project.js (a managed project)
11
+ // 4. service_id in fastly.toml
11
12
  // This is the same order as the Fastly CLI's --service-id.
12
13
  export function loadServiceId(params) {
13
14
  if (typeof params.commandLine === 'string' && params.commandLine.trim() !== '') {
@@ -17,6 +18,9 @@ export function loadServiceId(params) {
17
18
  if (envServiceId) {
18
19
  return { serviceId: envServiceId, source: 'env' };
19
20
  }
21
+ if (params.projectServiceId != null && params.projectServiceId.trim() !== '') {
22
+ return { serviceId: params.projectServiceId.trim(), source: 'managed.serviceId' };
23
+ }
20
24
  if (fs.existsSync(params.fastlyTomlPath)) {
21
25
  const serviceId = readServiceId(params.fastlyTomlPath);
22
26
  if (serviceId != null) {
@@ -1 +1 @@
1
- {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/variants.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAQ,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAGrE,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,uBAAuB,CAAC;AAK5D,qBAAa,UAAU,CAAC,CAAC;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiC;IAE1D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE;CAShF;AAED,wBAAsB,uBAAuB,CAC3C,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,eAAe,GAAE,eAAoB,iBA6BtC"}
1
+ {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/variants.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAQ,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAGrE,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,uBAAuB,CAAC;AAK5D,qBAAa,UAAU,CAAC,CAAC;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiC;IAE1D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAQ9E;CACF;AAED,wBAAsB,uBAAuB,CAC3C,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,eAAe,GAAE,eAAoB,iBA6BtC"}
@@ -7,6 +7,12 @@ export type AssetEntry = {
7
7
  variants: ContentCompressionTypes[];
8
8
  };
9
9
  export type AssetEntryMap = Record<string, AssetEntry>;
10
+ export declare const HIDDEN_INDEX_KEY_PREFIX = "hidden:";
11
+ export declare const HIDDEN_INDEX_FEATURE = "hidden";
12
+ export declare function hiddenIndexKey(assetKey: string): string;
13
+ export declare function isHiddenIndexKey(indexKey: string): boolean;
14
+ export declare function findAssetEntry(assetEntryMap: AssetEntryMap, assetKey: string, includeHidden: boolean): AssetEntry | null;
15
+ export declare function countHiddenEntries(assetEntryMap: AssetEntryMap): number;
10
16
  export type AssetVariantMetadata = {
11
17
  contentEncoding?: ContentCompressionTypes;
12
18
  size: number;