@fastly/compute-js-static-publish 6.2.0 → 7.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +31 -575
  3. package/README.short.md +53 -0
  4. package/build/cli/commands/clean.d.ts +2 -0
  5. package/build/cli/commands/clean.d.ts.map +1 -0
  6. package/build/cli/commands/clean.js +121 -0
  7. package/build/cli/commands/collections/delete.d.ts +2 -0
  8. package/build/cli/commands/collections/delete.d.ts.map +1 -0
  9. package/build/cli/commands/collections/delete.js +88 -0
  10. package/build/cli/commands/collections/index.d.ts +2 -0
  11. package/build/cli/commands/collections/index.d.ts.map +1 -0
  12. package/build/cli/commands/collections/index.js +52 -0
  13. package/build/cli/commands/collections/list.d.ts +2 -0
  14. package/build/cli/commands/collections/list.d.ts.map +1 -0
  15. package/build/cli/commands/collections/list.js +62 -0
  16. package/build/cli/commands/index.d.ts +2 -0
  17. package/build/cli/commands/index.d.ts.map +1 -0
  18. package/build/cli/commands/index.js +67 -0
  19. package/build/cli/commands/init-app.d.ts +18 -2
  20. package/build/cli/commands/init-app.d.ts.map +1 -1
  21. package/build/cli/commands/init-app.js +291 -264
  22. package/build/cli/commands/publish-content.d.ts +2 -0
  23. package/build/cli/commands/publish-content.d.ts.map +1 -0
  24. package/build/cli/commands/publish-content.js +472 -0
  25. package/build/cli/compression/brotli.d.ts +1 -1
  26. package/build/cli/compression/brotli.d.ts.map +1 -1
  27. package/build/cli/compression/brotli.js +8 -11
  28. package/build/cli/compression/gzip.d.ts +1 -1
  29. package/build/cli/compression/gzip.d.ts.map +1 -1
  30. package/build/cli/compression/gzip.js +8 -11
  31. package/build/cli/compression/index.d.ts +3 -6
  32. package/build/cli/compression/index.d.ts.map +1 -1
  33. package/build/cli/compression/index.js +8 -9
  34. package/build/cli/fastly-api/api-token.d.ts +17 -0
  35. package/build/cli/fastly-api/api-token.d.ts.map +1 -0
  36. package/build/cli/fastly-api/api-token.js +94 -0
  37. package/build/cli/fastly-api/kv-store.d.ts +24 -0
  38. package/build/cli/fastly-api/kv-store.d.ts.map +1 -0
  39. package/build/cli/{util → fastly-api}/kv-store.js +42 -22
  40. package/build/cli/index.js +7 -91
  41. package/build/cli/util/args.d.ts +16 -0
  42. package/build/cli/util/args.d.ts.map +1 -0
  43. package/build/cli/util/args.js +55 -0
  44. package/build/cli/util/config.d.ts +13 -0
  45. package/build/cli/util/config.d.ts.map +1 -0
  46. package/build/cli/{load-config.js → util/config.js} +234 -187
  47. package/build/{util → cli/util}/content-types.d.ts +1 -2
  48. package/build/cli/util/content-types.d.ts.map +1 -0
  49. package/build/{util → cli/util}/content-types.js +38 -32
  50. package/build/cli/util/data.d.ts +3 -3
  51. package/build/cli/util/data.d.ts.map +1 -1
  52. package/build/cli/util/data.js +6 -2
  53. package/build/cli/util/files.d.ts +10 -2
  54. package/build/cli/util/files.d.ts.map +1 -1
  55. package/build/cli/util/files.js +53 -6
  56. package/build/cli/util/kv-store-items.d.ts +12 -0
  57. package/build/cli/util/kv-store-items.d.ts.map +1 -0
  58. package/build/cli/util/kv-store-items.js +161 -0
  59. package/build/cli/util/kv-store-local-server.d.ts +3 -0
  60. package/build/cli/util/kv-store-local-server.d.ts.map +1 -0
  61. package/build/cli/util/kv-store-local-server.js +35 -0
  62. package/build/cli/util/package.d.ts +9 -0
  63. package/build/cli/util/package.d.ts.map +1 -0
  64. package/build/cli/util/package.js +44 -0
  65. package/build/cli/util/retryable.d.ts +12 -0
  66. package/build/cli/util/retryable.d.ts.map +1 -0
  67. package/build/cli/util/retryable.js +43 -0
  68. package/build/cli/util/variants.d.ts +4 -0
  69. package/build/cli/util/variants.d.ts.map +1 -0
  70. package/build/cli/util/variants.js +27 -0
  71. package/build/index.d.ts +5 -5
  72. package/build/index.d.ts.map +1 -1
  73. package/build/index.js +7 -6
  74. package/build/models/assets/kvstore-assets.d.ts +17 -0
  75. package/build/models/assets/kvstore-assets.d.ts.map +1 -0
  76. package/build/models/assets/kvstore-assets.js +28 -0
  77. package/build/{constants/compression.d.ts → models/compression/index.d.ts} +2 -1
  78. package/build/models/compression/index.d.ts.map +1 -0
  79. package/build/models/compression/index.js +11 -0
  80. package/build/models/config/publish-content-config.d.ts +41 -0
  81. package/build/models/config/publish-content-config.d.ts.map +1 -0
  82. package/build/models/config/publish-content-config.js +5 -0
  83. package/build/models/config/publisher-server-config.d.ts +20 -0
  84. package/build/models/config/publisher-server-config.d.ts.map +1 -0
  85. package/build/models/config/publisher-server-config.js +5 -0
  86. package/build/models/config/static-publish-rc.d.ts +6 -0
  87. package/build/models/config/static-publish-rc.d.ts.map +1 -0
  88. package/build/models/config/static-publish-rc.js +5 -0
  89. package/build/server/collection-selector/from-config-store.d.ts +2 -0
  90. package/build/server/collection-selector/from-config-store.d.ts.map +1 -0
  91. package/build/server/collection-selector/from-config-store.js +15 -0
  92. package/build/server/collection-selector/from-cookie.d.ts +23 -0
  93. package/build/server/collection-selector/from-cookie.d.ts.map +1 -0
  94. package/build/server/collection-selector/from-cookie.js +98 -0
  95. package/build/server/collection-selector/from-request.d.ts +13 -0
  96. package/build/server/collection-selector/from-request.d.ts.map +1 -0
  97. package/build/server/collection-selector/from-request.js +22 -0
  98. package/build/server/collection-selector/index.d.ts +5 -0
  99. package/build/server/collection-selector/index.d.ts.map +1 -0
  100. package/build/server/collection-selector/index.js +7 -0
  101. package/build/server/collection-selector/request-collection-selector.d.ts +5 -0
  102. package/build/server/collection-selector/request-collection-selector.d.ts.map +1 -0
  103. package/build/server/collection-selector/request-collection-selector.js +5 -0
  104. package/build/server/publisher-server/index.d.ts +38 -0
  105. package/build/server/publisher-server/index.d.ts.map +1 -0
  106. package/build/server/publisher-server/index.js +415 -0
  107. package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts +3 -0
  108. package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +1 -0
  109. package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-modified-since.js +6 -2
  110. package/build/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +1 -0
  111. package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-none-match.js +4 -0
  112. package/build/server/util/cookies.d.ts +2 -0
  113. package/build/server/util/cookies.d.ts.map +1 -0
  114. package/build/server/util/cookies.js +14 -0
  115. package/build/server/util/kv-store.d.ts +3 -0
  116. package/build/server/util/kv-store.d.ts.map +1 -0
  117. package/build/server/util/kv-store.js +95 -0
  118. package/package.json +18 -10
  119. package/build/cli/commands/build-static.d.ts +0 -3
  120. package/build/cli/commands/build-static.d.ts.map +0 -1
  121. package/build/cli/commands/build-static.js +0 -541
  122. package/build/cli/commands/clean-kv-store.d.ts +0 -3
  123. package/build/cli/commands/clean-kv-store.d.ts.map +0 -1
  124. package/build/cli/commands/clean-kv-store.js +0 -55
  125. package/build/cli/load-config.d.ts +0 -6
  126. package/build/cli/load-config.d.ts.map +0 -1
  127. package/build/cli/presets/implementations/astro.d.ts +0 -7
  128. package/build/cli/presets/implementations/astro.d.ts.map +0 -1
  129. package/build/cli/presets/implementations/astro.js +0 -23
  130. package/build/cli/presets/implementations/create-react-app.d.ts +0 -11
  131. package/build/cli/presets/implementations/create-react-app.d.ts.map +0 -1
  132. package/build/cli/presets/implementations/create-react-app.js +0 -34
  133. package/build/cli/presets/implementations/docusaurus.d.ts +0 -7
  134. package/build/cli/presets/implementations/docusaurus.d.ts.map +0 -1
  135. package/build/cli/presets/implementations/docusaurus.js +0 -13
  136. package/build/cli/presets/implementations/gatsby.d.ts +0 -7
  137. package/build/cli/presets/implementations/gatsby.d.ts.map +0 -1
  138. package/build/cli/presets/implementations/gatsby.js +0 -13
  139. package/build/cli/presets/implementations/next.d.ts +0 -7
  140. package/build/cli/presets/implementations/next.d.ts.map +0 -1
  141. package/build/cli/presets/implementations/next.js +0 -13
  142. package/build/cli/presets/implementations/sveltekit.d.ts +0 -7
  143. package/build/cli/presets/implementations/sveltekit.d.ts.map +0 -1
  144. package/build/cli/presets/implementations/sveltekit.js +0 -13
  145. package/build/cli/presets/implementations/vite.d.ts +0 -7
  146. package/build/cli/presets/implementations/vite.d.ts.map +0 -1
  147. package/build/cli/presets/implementations/vite.js +0 -13
  148. package/build/cli/presets/implementations/vue.d.ts +0 -7
  149. package/build/cli/presets/implementations/vue.d.ts.map +0 -1
  150. package/build/cli/presets/implementations/vue.js +0 -24
  151. package/build/cli/presets/index.d.ts +0 -3
  152. package/build/cli/presets/index.d.ts.map +0 -1
  153. package/build/cli/presets/index.js +0 -20
  154. package/build/cli/presets/preset-base.d.ts +0 -21
  155. package/build/cli/presets/preset-base.d.ts.map +0 -1
  156. package/build/cli/presets/preset-base.js +0 -1
  157. package/build/cli/util/fastly-api.d.ts +0 -10
  158. package/build/cli/util/fastly-api.d.ts.map +0 -1
  159. package/build/cli/util/fastly-api.js +0 -47
  160. package/build/cli/util/hash.d.ts +0 -5
  161. package/build/cli/util/hash.d.ts.map +0 -1
  162. package/build/cli/util/hash.js +0 -9
  163. package/build/cli/util/id.d.ts +0 -3
  164. package/build/cli/util/id.d.ts.map +0 -1
  165. package/build/cli/util/id.js +0 -17
  166. package/build/cli/util/kv-store.d.ts +0 -16
  167. package/build/cli/util/kv-store.d.ts.map +0 -1
  168. package/build/cli/util/publish-id.d.ts +0 -5
  169. package/build/cli/util/publish-id.d.ts.map +0 -1
  170. package/build/cli/util/publish-id.js +0 -26
  171. package/build/compute-js.d.ts +0 -3
  172. package/build/compute-js.d.ts.map +0 -1
  173. package/build/compute-js.js +0 -2
  174. package/build/constants/compression.d.ts.map +0 -1
  175. package/build/constants/compression.js +0 -4
  176. package/build/server/assets/asset-manager.d.ts +0 -8
  177. package/build/server/assets/asset-manager.d.ts.map +0 -1
  178. package/build/server/assets/asset-manager.js +0 -14
  179. package/build/server/assets/content-asset-kv-store.d.ts +0 -19
  180. package/build/server/assets/content-asset-kv-store.d.ts.map +0 -1
  181. package/build/server/assets/content-asset-kv-store.js +0 -70
  182. package/build/server/assets/content-asset-wasm-inline.d.ts +0 -18
  183. package/build/server/assets/content-asset-wasm-inline.d.ts.map +0 -1
  184. package/build/server/assets/content-asset-wasm-inline.js +0 -52
  185. package/build/server/assets/content-assets.d.ts +0 -46
  186. package/build/server/assets/content-assets.d.ts.map +0 -1
  187. package/build/server/assets/content-assets.js +0 -100
  188. package/build/server/assets/module-assets.d.ts +0 -23
  189. package/build/server/assets/module-assets.d.ts.map +0 -1
  190. package/build/server/assets/module-assets.js +0 -45
  191. package/build/server/kv-store/inline-store-entry.d.ts +0 -25
  192. package/build/server/kv-store/inline-store-entry.d.ts.map +0 -1
  193. package/build/server/kv-store/inline-store-entry.js +0 -100
  194. package/build/server/publisher-server.d.ts +0 -23
  195. package/build/server/publisher-server.d.ts.map +0 -1
  196. package/build/server/publisher-server.js +0 -257
  197. package/build/server/serve-preconditions/if-modified-since.d.ts +0 -4
  198. package/build/server/serve-preconditions/if-modified-since.d.ts.map +0 -1
  199. package/build/server/serve-preconditions/if-none-match.d.ts.map +0 -1
  200. package/build/server/util/http.d.ts +0 -2
  201. package/build/server/util/http.d.ts.map +0 -1
  202. package/build/server/util/http.js +0 -9
  203. package/build/types/compute.d.ts +0 -11
  204. package/build/types/compute.d.ts.map +0 -1
  205. package/build/types/compute.js +0 -1
  206. package/build/types/config-normalized.d.ts +0 -34
  207. package/build/types/config-normalized.d.ts.map +0 -1
  208. package/build/types/config-normalized.js +0 -1
  209. package/build/types/config.d.ts +0 -37
  210. package/build/types/config.d.ts.map +0 -1
  211. package/build/types/config.js +0 -1
  212. package/build/types/content-assets.d.ts +0 -55
  213. package/build/types/content-assets.d.ts.map +0 -1
  214. package/build/types/content-assets.js +0 -1
  215. package/build/types/content-types.d.ts +0 -11
  216. package/build/types/content-types.d.ts.map +0 -1
  217. package/build/types/content-types.js +0 -1
  218. package/build/types/index.d.ts +0 -7
  219. package/build/types/index.d.ts.map +0 -1
  220. package/build/types/index.js +0 -1
  221. package/build/types/module-assets.d.ts +0 -15
  222. package/build/types/module-assets.d.ts.map +0 -1
  223. package/build/types/module-assets.js +0 -1
  224. package/build/types/util.d.ts +0 -7
  225. package/build/types/util.d.ts.map +0 -1
  226. package/build/types/util.js +0 -1
  227. package/build/util/content-types.d.ts.map +0 -1
  228. package/build/util/index.d.ts +0 -3
  229. package/build/util/index.d.ts.map +0 -1
  230. package/build/util/index.js +0 -2
  231. package/build/util/metadata.d.ts +0 -3
  232. package/build/util/metadata.d.ts.map +0 -1
  233. package/build/util/metadata.js +0 -12
  234. package/resources/README.md +0 -3
  235. package/resources/statics-metadata.d.ts +0 -10
  236. package/resources/statics.d.ts +0 -19
  237. package/resources/webpack.config.js +0 -33
  238. /package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-none-match.d.ts +0 -0
@@ -0,0 +1,94 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { spawnSync } from 'node:child_process';
6
+ import cli from '@fastly/cli';
7
+ import { makeRetryable } from '../util/retryable.js';
8
+ ;
9
+ export function loadApiToken(params) {
10
+ let apiToken = null;
11
+ let source = '';
12
+ // Try command line arg
13
+ if (typeof params.commandLine === 'string') {
14
+ apiToken = params.commandLine.trim();
15
+ source = 'commandline';
16
+ }
17
+ // Try env (FASTLY_API_TOKEN)
18
+ if (apiToken == null) {
19
+ apiToken = process.env.FASTLY_API_TOKEN || null;
20
+ if (apiToken != null) {
21
+ source = 'env';
22
+ }
23
+ }
24
+ // Try fastly cli
25
+ if (apiToken == null) {
26
+ try {
27
+ const { stdout, error } = spawnSync(cli, ['profile', 'token', '--quiet'], {
28
+ encoding: 'utf-8',
29
+ });
30
+ apiToken = error ? null : stdout.trim();
31
+ }
32
+ catch {
33
+ apiToken = null;
34
+ }
35
+ if (apiToken != null) {
36
+ source = 'fastly-profile-token';
37
+ }
38
+ }
39
+ if (apiToken == null) {
40
+ return null;
41
+ }
42
+ return { apiToken, source };
43
+ }
44
+ const RETRYABLE_STATUS_CODES = [
45
+ 408, // Request Timeout
46
+ 409, // Conflict (depends)
47
+ 423, // Locked
48
+ 429, // Too Many Requests
49
+ 500, // Internal Server Error
50
+ 502, // Bad Gateway
51
+ 503, // Service Unavailable
52
+ 504, // Gateway Timeout
53
+ ];
54
+ export class FetchError extends Error {
55
+ constructor(message, status) {
56
+ super(message);
57
+ this.name = 'FetchError';
58
+ this.status = status;
59
+ }
60
+ }
61
+ export async function callFastlyApi(fastlyApiContext, endpoint, operationName, queryParams, requestInit) {
62
+ const url = new URL(endpoint, 'https://api.fastly.com/');
63
+ if (queryParams != null) {
64
+ for (const [key, value] of queryParams.entries()) {
65
+ url.searchParams.append(key, value);
66
+ }
67
+ }
68
+ const headers = new Headers(requestInit?.headers);
69
+ headers.set('Fastly-Key', fastlyApiContext.apiToken);
70
+ const request = new Request(url, {
71
+ ...requestInit,
72
+ headers,
73
+ redirect: 'error',
74
+ });
75
+ let response;
76
+ try {
77
+ response = await fetch(request);
78
+ }
79
+ catch (err) {
80
+ if (err instanceof TypeError) {
81
+ throw makeRetryable(err);
82
+ }
83
+ else {
84
+ throw err;
85
+ }
86
+ }
87
+ if (!response.ok) {
88
+ if (!RETRYABLE_STATUS_CODES.includes(response.status)) {
89
+ throw new FetchError(`${operationName} failed: ${response.status}`, response.status);
90
+ }
91
+ throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${response.status}`, response.status));
92
+ }
93
+ return response;
94
+ }
@@ -0,0 +1,24 @@
1
+ import { type FastlyApiContext } from './api-token.js';
2
+ type KVStoreInfo = {
3
+ id: string;
4
+ name: string;
5
+ };
6
+ export declare function getKVStoreIdForNameMap(fastlyApiContext: FastlyApiContext): Promise<Record<string, string>>;
7
+ export declare function getKVStoreIdForName(fastlyApiContext: FastlyApiContext, kvStoreName: string): Promise<string>;
8
+ export declare function getKVStoreInfos(fastlyApiContext: FastlyApiContext): Promise<KVStoreInfo[]>;
9
+ export declare const _getKVStoreKeys: (fastlyApiContext: FastlyApiContext, operationName: string, kvStoreId: string, prefix?: string | undefined) => Promise<string[]>;
10
+ export declare function getKVStoreKeys(fastlyApiContext: FastlyApiContext, kvStoreName: string, prefix?: string): Promise<string[] | null>;
11
+ export declare function getKvStoreEntryInfo(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<false | {
12
+ metadata: string | null;
13
+ generation: string | null;
14
+ response: Response;
15
+ }>;
16
+ export declare function getKvStoreEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, metadataOnly?: boolean): Promise<false | {
17
+ metadata: string | null;
18
+ generation: string | null;
19
+ response: Response;
20
+ }>;
21
+ export declare function kvStoreSubmitFile(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, data: Uint8Array | string, metadata: string | undefined): Promise<void>;
22
+ export declare function kvStoreDeleteFile(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<void>;
23
+ export {};
24
+ //# sourceMappingURL=kv-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kv-store.d.ts","sourceRoot":"","sources":["../../../src/cli/fastly-api/kv-store.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,KAAK,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAElF,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAmBF,wBAAsB,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,mCAkB9E;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,mBAKhG;AAqCD,wBAAsB,eAAe,CAAC,gBAAgB,EAAE,gBAAgB,0BAcvE;AAED,eAAO,MAAM,eAAe,qBAjDgB,gBAAgB,iBAAiB,MAAM,sEAyDlF,CAAC;AAEF,wBAAsB,cAAc,CAClC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,4BAchB;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;;;;GAI7G;AAED,wBAAsB,eAAe,CACnC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,OAAO;;;;GA8BvB;AAGD,wBAAsB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,iBAmBpK;AAED,wBAAsB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,iBAa3G"}
@@ -1,4 +1,8 @@
1
- import { callFastlyApi } from "./fastly-api.js";
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { callFastlyApi, FetchError } from './api-token.js';
2
6
  const cache = new WeakMap();
3
7
  export async function getKVStoreIdForNameMap(fastlyApiContext) {
4
8
  const cacheEntry = cache.get(fastlyApiContext);
@@ -20,7 +24,7 @@ export async function getKVStoreIdForName(fastlyApiContext, kvStoreName) {
20
24
  }
21
25
  function createArrayGetter() {
22
26
  return function (fn) {
23
- return async function (fastlyApiContext, ...args) {
27
+ return async function (fastlyApiContext, operationName, ...args) {
24
28
  const results = [];
25
29
  let cursor = null;
26
30
  while (true) {
@@ -29,10 +33,7 @@ function createArrayGetter() {
29
33
  queryParams.set('cursor', cursor);
30
34
  }
31
35
  const endpoint = fn(...args);
32
- const response = await callFastlyApi(fastlyApiContext, endpoint, queryParams);
33
- if (response.status !== 200) {
34
- throw new Error('Unexpected data format');
35
- }
36
+ const response = await callFastlyApi(fastlyApiContext, endpoint, operationName, queryParams);
36
37
  const infos = await response.json();
37
38
  for (const item of infos.data) {
38
39
  results.push(item);
@@ -53,45 +54,67 @@ export async function getKVStoreInfos(fastlyApiContext) {
53
54
  if (kvStoreInfos != null) {
54
55
  return kvStoreInfos;
55
56
  }
56
- kvStoreInfos = await _getKVStoreInfos(fastlyApiContext);
57
+ kvStoreInfos = await _getKVStoreInfos(fastlyApiContext, 'Listing KV Stores');
57
58
  cache.set(fastlyApiContext, { ...cacheEntry, kvStoreInfos });
58
59
  return kvStoreInfos;
59
60
  }
60
- export const _getKVStoreKeys = createArrayGetter()((kvStoreId) => `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys`);
61
- export async function getKVStoreKeys(fastlyApiContext, kvStoreName) {
61
+ export const _getKVStoreKeys = createArrayGetter()((kvStoreId, prefix) => {
62
+ let endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys`;
63
+ if (prefix != null) {
64
+ endpoint += '?prefix=' + encodeURIComponent(prefix);
65
+ }
66
+ return endpoint;
67
+ });
68
+ export async function getKVStoreKeys(fastlyApiContext, kvStoreName, prefix) {
62
69
  const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
63
70
  if (kvStoreId == null) {
64
71
  return null;
65
72
  }
66
- return await _getKVStoreKeys(fastlyApiContext, kvStoreId);
73
+ return await _getKVStoreKeys(fastlyApiContext, `Listing Keys for KV Store [${kvStoreId}] ${kvStoreName}${prefix != null ? ` (prefix '${prefix}')` : ''}`, kvStoreId, prefix);
67
74
  }
68
- export async function kvStoreEntryExists(fastlyApiContext, kvStoreName, key) {
75
+ export async function getKvStoreEntryInfo(fastlyApiContext, kvStoreName, key) {
76
+ return getKvStoreEntry(fastlyApiContext, kvStoreName, key, true);
77
+ }
78
+ export async function getKvStoreEntry(fastlyApiContext, kvStoreName, key, metadataOnly) {
69
79
  const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
70
80
  if (kvStoreId == null) {
71
81
  return false;
72
82
  }
73
83
  const endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys/${encodeURIComponent(key)}`;
74
- const response = await callFastlyApi(fastlyApiContext, endpoint, null, { method: 'HEAD' });
75
- return response.status === 200;
84
+ let response;
85
+ try {
86
+ response = await callFastlyApi(fastlyApiContext, endpoint, `Checking existence of [${key}]`, null, { method: metadataOnly ? 'HEAD' : 'GET' });
87
+ }
88
+ catch (err) {
89
+ if (err instanceof FetchError && err.status === 404) {
90
+ return false;
91
+ }
92
+ throw err;
93
+ }
94
+ const metadata = response.headers.get('metadata');
95
+ const generation = response.headers.get('generation');
96
+ return {
97
+ metadata,
98
+ generation,
99
+ response,
100
+ };
76
101
  }
77
102
  const encoder = new TextEncoder();
78
- export async function kvStoreSubmitFile(fastlyApiContext, kvStoreName, key, data) {
103
+ export async function kvStoreSubmitFile(fastlyApiContext, kvStoreName, key, data, metadata) {
79
104
  const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
80
105
  if (kvStoreId == null) {
81
106
  throw new Error('KV Store not found');
82
107
  }
83
108
  const endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys/${encodeURIComponent(key)}`;
84
109
  const body = typeof data === 'string' ? encoder.encode(data) : data;
85
- const response = await callFastlyApi(fastlyApiContext, endpoint, null, {
110
+ await callFastlyApi(fastlyApiContext, endpoint, `Submitting item [${key}]`, null, {
86
111
  method: 'PUT',
87
112
  headers: {
88
113
  'content-type': 'application/octet-stream',
114
+ ...(metadata != null ? { metadata } : null)
89
115
  },
90
116
  body,
91
117
  });
92
- if (response.status !== 200) {
93
- throw new Error(`Submitting item ${key} gave error: ${response.status}`);
94
- }
95
118
  }
96
119
  export async function kvStoreDeleteFile(fastlyApiContext, kvStoreName, key) {
97
120
  const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
@@ -99,10 +122,7 @@ export async function kvStoreDeleteFile(fastlyApiContext, kvStoreName, key) {
99
122
  throw new Error('KV Store not found');
100
123
  }
101
124
  const endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys/${encodeURIComponent(key)}`;
102
- const response = await callFastlyApi(fastlyApiContext, endpoint, null, {
125
+ await callFastlyApi(fastlyApiContext, endpoint, `Deleting item [${key}]`, null, {
103
126
  method: 'DELETE',
104
127
  });
105
- if (response.status < 200 || response.status >= 300) {
106
- throw new Error(`Deleting item '${key}' gave error: ${response.status}`);
107
- }
108
128
  }
@@ -1,92 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import commandLineArgs from "command-line-args";
3
- import { initApp } from "./commands/init-app.js";
4
- import { buildStaticLoader } from "./commands/build-static.js";
5
- import { cleanKVStore } from "./commands/clean-kv-store.js";
6
- const optionDefinitions = [
7
- // (optional) Should be one of:
8
- // - cra (or create-react-app)
9
- // - vite
10
- // - sveltekit
11
- // - vue
12
- // - next
13
- // - astro
14
- // - gatsby
15
- // - docusaurus
16
- { name: 'preset', type: String, },
17
- { name: 'build-static', type: Boolean },
18
- { name: 'suppress-framework-warnings', type: Boolean },
19
- { name: 'output', alias: 'o', type: String, defaultValue: './compute-js', },
20
- // Whether the scaffolded project should use Webpack to bundle assets.
21
- { name: 'webpack', type: Boolean, defaultValue: false },
22
- // The 'root' directory for the publishing.
23
- // All assets are expected to exist under this root. Required.
24
- // For backwards compatibility, if this value is not provided,
25
- // then the value of 'public-dir' is used.
26
- { name: 'root-dir', type: String, },
27
- // The 'public' directory. The Publisher Server will
28
- // resolve requests relative to this directory. If not specified,
29
- // defaults to the same value as 'root-dir'. See README for
30
- // details.
31
- { name: 'public-dir', type: String, },
32
- // Directories to specify as containing 'static' files. The
33
- // Publisher Server will serve files from these directories
34
- // with a long TTL.
35
- { name: 'static-dir', type: String, multiple: true, },
36
- // The 'static content root directory' where the Static Publisher
37
- // outputs its metadata files and loaders.
38
- { name: 'static-content-root-dir', type: String, },
39
- // Path to a file to be used to serve in a SPA application.
40
- // The Publisher Server will serve this file with a 200 status code
41
- // when the request doesn't match a known file, and the accept
42
- // header includes text/html. You may use the '[public-dir]' token
43
- // if you wish to specify this as a relative path from the 'public-dir'.
44
- { name: 'spa', type: String, },
45
- // Path to a file to be used to serve as a 404 not found page.
46
- // The Publisher Server will serve this file with a 404 status code
47
- // when the request doesn't match a known file, and the accept
48
- // header includes text/html. You may use the '[public-dir]' token
49
- // if you wish to specify this as a relative path from the 'public-dir'.
50
- { name: 'not-found-page', type: String, },
51
- // List of files to automatically use as index, for example, index.html,index.htm
52
- // If a request comes in but the route does not exist, we check the route
53
- // plus a slash plus the items in this array.
54
- { name: 'auto-index', type: String, multiple: true, },
55
- // List of extensions to apply to a path name, for example, if
56
- // http://example.com/about is requested, we can respond with http://example.com/about.html
57
- { name: 'auto-ext', type: String, multiple: true, },
58
- // Components from fastly.toml
59
- // Name of the application, to be inserted into fastly.toml
60
- { name: 'name', type: String, },
61
- // Name of the author, to be inserted into fastly.toml
62
- { name: 'author', type: String, },
63
- // Description of the application, to be inserted into fastly.toml
64
- { name: 'description', type: String, },
65
- // Fastly Service ID to be added to the fastly.toml that is generated.
66
- { name: 'service-id', type: String },
67
- // The name of a Fastly KV Store to hold the content assets.
68
- // It must be linked to the service specified by `--service-id`.
69
- { name: 'kv-store-name', type: String },
70
- // Clean KV Store mode
71
- { name: 'clean-kv-store', type: Boolean, },
72
- ];
73
- const commandLineValues = commandLineArgs(optionDefinitions);
74
- console.log("Fastly Compute JavaScript Static Publisher");
75
- let mode = 'init-app';
76
- if (commandLineValues['build-static']) {
77
- mode = 'build-static';
78
- }
79
- else if (commandLineValues['clean-kv-store']) {
80
- mode = 'clean-kv-store';
81
- }
82
- switch (mode) {
83
- case 'build-static':
84
- await buildStaticLoader(commandLineValues);
85
- break;
86
- case 'init-app':
87
- initApp(commandLineValues);
88
- break;
89
- case 'clean-kv-store':
90
- await cleanKVStore(commandLineValues);
91
- break;
92
- }
2
+ /*
3
+ * Copyright Fastly, Inc.
4
+ * Licensed under the MIT license. See LICENSE file for details.
5
+ */
6
+ import { action } from './commands/index.js';
7
+ console.log("🧑‍💻 Fastly Compute JavaScript Static Publisher");
8
+ await action(process.argv);
@@ -0,0 +1,16 @@
1
+ export type ModeAction = (argv: string[]) => void | Promise<void>;
2
+ export type ActionModule = {
3
+ action: ModeAction;
4
+ };
5
+ export declare function isHelpArgs(argv: string[]): boolean;
6
+ export declare function findMainCommandNameAndArgs(argv: string[]): [string | null, string[]];
7
+ export type CommandAndArgs<T> = {
8
+ needHelp: false;
9
+ command: T;
10
+ argv: string[];
11
+ } | {
12
+ needHelp: true;
13
+ command: string | null;
14
+ };
15
+ export declare function getCommandAndArgs<T extends string>(argv: string[], modes: T[]): CommandAndArgs<T>;
16
+ //# sourceMappingURL=args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../src/cli/util/args.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAElD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,WAQxC;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAepF;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,IAC1B;IACA,QAAQ,EAAE,KAAK,CAAC;IAChB,OAAO,EAAE,CAAC,CAAC;IACX,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,GACC;IACA,QAAQ,EAAE,IAAI,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CACA;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,CAAC,EAAE,GACT,cAAc,CAAC,CAAC,CAAC,CAiCnB"}
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import commandLineArgs from 'command-line-args';
6
+ export function isHelpArgs(argv) {
7
+ const helpDefinitions = [
8
+ { name: 'help', type: Boolean, },
9
+ ];
10
+ const helpOptions = commandLineArgs(helpDefinitions, { argv, stopAtFirstUnknown: true });
11
+ return !!helpOptions['help'];
12
+ }
13
+ export function findMainCommandNameAndArgs(argv) {
14
+ const mainDefinitions = [
15
+ { name: 'command', type: String, defaultOption: true },
16
+ ];
17
+ const mainOptions = commandLineArgs(mainDefinitions, { argv, stopAtFirstUnknown: true });
18
+ const commandArgs = mainOptions._unknown || [];
19
+ const command = mainOptions['command'];
20
+ if (typeof command !== 'string') {
21
+ return [null, commandArgs];
22
+ }
23
+ return [command, commandArgs];
24
+ }
25
+ export function getCommandAndArgs(argv, modes) {
26
+ if (isHelpArgs(argv)) {
27
+ return {
28
+ needHelp: true,
29
+ command: null,
30
+ };
31
+ }
32
+ const result = findMainCommandNameAndArgs(argv);
33
+ const [command, actionArgv] = result;
34
+ if (command != null) {
35
+ for (const modeName of modes) {
36
+ if (command === modeName) {
37
+ return {
38
+ needHelp: false,
39
+ command: command,
40
+ argv: actionArgv,
41
+ };
42
+ }
43
+ }
44
+ }
45
+ try {
46
+ commandLineArgs([], { argv: actionArgv });
47
+ }
48
+ catch (err) {
49
+ console.log(String(err));
50
+ }
51
+ return {
52
+ needHelp: true,
53
+ command,
54
+ };
55
+ }
@@ -0,0 +1,13 @@
1
+ import { type PublishContentConfigNormalized } from '../../models/config/publish-content-config.js';
2
+ import { type PublisherServerConfigNormalized } from '../../models/config/publisher-server-config.js';
3
+ import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
4
+ export declare class LoadConfigError extends Error {
5
+ errors: string[];
6
+ constructor(configFilePath: string, errors: string[]);
7
+ }
8
+ export declare function loadStaticPublisherRcFile(): Promise<StaticPublishRc>;
9
+ export declare const normalizeStaticPublisherRc: (obj: unknown, errCtx?: string[]) => StaticPublishRc | null;
10
+ export declare function loadPublishContentConfigFile(configFile: string): Promise<PublishContentConfigNormalized>;
11
+ export declare const normalizePublishContentConfig: (obj: unknown, errCtx?: string[]) => PublishContentConfigNormalized | null;
12
+ export declare const normalizePublisherServerConfig: (obj: unknown, errCtx?: string[]) => PublisherServerConfigNormalized | null;
13
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/cli/util/config.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,8BAA8B,EAEpC,MAAM,+CAA+C,CAAC;AAOvD,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AACtG,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEhF,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,CA2B1E;AAGD,eAAO,MAAM,0BAA0B,6DA2CrC,CAAC;AAEH,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAyB9G;AA4CD,eAAO,MAAM,6BAA6B,4EAuKxC,CAAC;AAEH,eAAO,MAAM,8BAA8B,6EAkIzC,CAAC"}