@fastly/compute-js-static-publish 8.0.0-rc.1 → 8.0.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 (53) hide show
  1. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  2. package/build/cli/cli/commands/manage/clean.js +1 -0
  3. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
  4. package/build/cli/cli/commands/manage/collections/delete.js +39 -2
  5. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
  6. package/build/cli/cli/commands/manage/collections/index.js +1 -0
  7. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
  8. package/build/cli/cli/commands/manage/collections/list.js +10 -1
  9. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  10. package/build/cli/cli/commands/manage/collections/promote.js +1 -0
  11. package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
  12. package/build/cli/cli/commands/manage/collections/update-expiration.js +1 -0
  13. package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
  14. package/build/cli/cli/commands/manage/index.js +1 -0
  15. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  16. package/build/cli/cli/commands/manage/publish-content.js +69 -74
  17. package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
  18. package/build/cli/cli/commands/scaffold/index.js +32 -13
  19. package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
  20. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  21. package/build/cli/cli/storage/s3-storage-provider.js +8 -4
  22. package/build/cli/cli/util/purge.d.ts +1 -0
  23. package/build/cli/cli/util/purge.d.ts.map +1 -1
  24. package/build/cli/cli/util/purge.js +21 -6
  25. package/build/cli/cli/util/service-id.js +1 -1
  26. package/build/cli/cli/util/variants.d.ts +7 -0
  27. package/build/cli/cli/util/variants.d.ts.map +1 -1
  28. package/build/cli/cli/util/variants.js +17 -0
  29. package/build/cli/models/config/publisher-server-config.d.ts +1 -0
  30. package/build/cli/models/config/publisher-server-config.d.ts.map +1 -1
  31. package/build/cli/models/server/index.d.ts +4 -0
  32. package/build/cli/models/server/index.d.ts.map +1 -1
  33. package/build/cli/models/server/index.js +34 -1
  34. package/build/server/models/config/publisher-server-config.d.ts +1 -0
  35. package/build/server/models/config/publisher-server-config.d.ts.map +1 -1
  36. package/build/server/models/server/index.d.ts +4 -0
  37. package/build/server/models/server/index.d.ts.map +1 -1
  38. package/build/server/models/server/index.js +34 -1
  39. package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -1
  40. package/build/server/server/collection-selector/from-cookie.js +28 -2
  41. package/build/server/server/publisher-server/index.d.ts +0 -1
  42. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  43. package/build/server/server/publisher-server/index.js +62 -52
  44. package/build/server/server/publisher-server/response-cache.d.ts +13 -0
  45. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
  46. package/build/server/server/publisher-server/response-cache.js +54 -0
  47. package/build/server/server/storage/s3-storage-provider.d.ts +6 -1
  48. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
  49. package/build/server/server/storage/s3-storage-provider.js +12 -7
  50. package/build/server/server/util/body-length.d.ts +5 -0
  51. package/build/server/server/util/body-length.d.ts.map +1 -0
  52. package/build/server/server/util/body-length.js +63 -0
  53. package/package.json +3 -3
@@ -3,6 +3,7 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import { compressionTypes, } from '../../models/compression/index.js';
6
+ export const DEFAULT_MAX_BODY_SIZE = 8 * 1024 * 1024;
6
7
  // Statuses that serveAsset() produces for a found file or a not-found page.
7
8
  // Anything else (for example, a 500 when the settings are missing) is not cached.
8
9
  export const CACHEABLE_STATUSES = [200, 404];
@@ -86,6 +87,56 @@ export function buildCacheFillRequest(request) {
86
87
  }
87
88
  return new Request(request.url, { method: 'GET', headers });
88
89
  }
90
+ // Reads body completely if it has maxLength bytes or fewer, and returns the bytes.
91
+ // Otherwise it stops reading, and returns a stream with all the bytes of body,
92
+ // including the bytes that it read. An error from body rejects the promise, or,
93
+ // after the limit, errors the stream.
94
+ export async function readBodyUpTo(body, maxLength) {
95
+ if (body == null) {
96
+ return { bytes: new Uint8Array(0) };
97
+ }
98
+ const reader = body.getReader();
99
+ const chunks = [];
100
+ let length = 0;
101
+ for (;;) {
102
+ const { done, value } = await reader.read();
103
+ if (done) {
104
+ break;
105
+ }
106
+ chunks.push(value);
107
+ length += value.byteLength;
108
+ if (length > maxLength) {
109
+ return {
110
+ body: new ReadableStream({
111
+ async pull(controller) {
112
+ const chunk = chunks.shift();
113
+ if (chunk != null) {
114
+ controller.enqueue(chunk);
115
+ return;
116
+ }
117
+ const result = await reader.read();
118
+ if (result.done) {
119
+ controller.close();
120
+ }
121
+ else {
122
+ controller.enqueue(result.value);
123
+ }
124
+ },
125
+ async cancel(reason) {
126
+ await reader.cancel(reason);
127
+ },
128
+ }),
129
+ };
130
+ }
131
+ }
132
+ const bytes = new Uint8Array(length);
133
+ let offset = 0;
134
+ for (const chunk of chunks) {
135
+ bytes.set(chunk, offset);
136
+ offset += chunk.byteLength;
137
+ }
138
+ return { bytes };
139
+ }
89
140
  export function encodeCachedResponseMetadata(metadata) {
90
141
  return JSON.stringify(metadata);
91
142
  }
@@ -95,6 +146,9 @@ export function decodeCachedResponseMetadata(buffer) {
95
146
  if (value?.notFound === true) {
96
147
  return { notFound: true };
97
148
  }
149
+ if (value?.tooLarge === true) {
150
+ return { tooLarge: true };
151
+ }
98
152
  if (typeof value?.status === 'number' && Array.isArray(value.headers)) {
99
153
  return { status: value.status, headers: value.headers };
100
154
  }
@@ -5,7 +5,12 @@ export type S3Credentials = {
5
5
  };
6
6
  export type S3CredentialsBuilder = () => (S3Credentials | Promise<S3Credentials>);
7
7
  export declare const buildStoreProvider: StorageProviderBuilder;
8
- export declare function setSecretStoreForS3Credentials(secretStoreName: string): void;
8
+ /**
9
+ * Sets the resource link name of the Secret Store that has the S3 credentials.
10
+ * This is the name of the link between the service and the Secret Store, not
11
+ * the name of the Secret Store. The default is 'S3_CREDENTIALS'.
12
+ */
13
+ export declare function setSecretStoreForS3Credentials(resourceLinkName: string): void;
9
14
  export declare function setSecretStoreKeyForS3AccessKeyId(secretStoreKey: string): void;
10
15
  export declare function setSecretStoreKeyForS3SecretAccessKey(secretStoreKey: string): void;
11
16
  export declare function buildS3CredentialsFromSecretStore(): Promise<S3Credentials>;
@@ -1 +1 @@
1
- {"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/server/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAiBA,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,eAAe,EACpB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;AAElF,eAAO,MAAM,kBAAkB,EAAE,sBAahC,CAAC;AAMF,wBAAgB,8BAA8B,CAAC,eAAe,EAAE,MAAM,QAErE;AAED,wBAAgB,iCAAiC,CAAC,cAAc,EAAE,MAAM,QAEvE;AAED,wBAAgB,qCAAqC,CAAC,cAAc,EAAE,MAAM,QAE3E;AAGD,wBAAsB,iCAAiC,2BA2BtD;AAGD,wBAAgB,uBAAuB,CAAC,oBAAoB,EAAE,oBAAoB,QAEjF;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAuBF,qBAAa,iBAAkB,YAAW,eAAe;gBAErD,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,uBAAuB;IAQlC,OAAO,CAAC,QA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M,CAAC;CAC9B,CAAC;AAuBF,qBAAa,iBAAkB,YAAW,eAAe;gBAErD,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,uBAAuB;IAQlC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAS;IAI9C,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG;IAYrB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAqDrE,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;CAkC3E"}
@@ -19,11 +19,16 @@ export const buildStoreProvider = (config) => {
19
19
  s3FastlyBackendName: s3StorageConfig.fastlyBackendName,
20
20
  });
21
21
  };
22
- let _secretStoreForS3Credentials = 'S3_CREDENTIALS';
22
+ let _secretStoreLinkNameForS3Credentials = 'S3_CREDENTIALS';
23
23
  let _secretStoreKeyForS3AccessKeyId = 'S3_ACCESS_KEY_ID';
24
24
  let _secretStoreKeyForS3SecretAccessKey = 'S3_SECRET_ACCESS_KEY';
25
- export function setSecretStoreForS3Credentials(secretStoreName) {
26
- _secretStoreForS3Credentials = secretStoreName;
25
+ /**
26
+ * Sets the resource link name of the Secret Store that has the S3 credentials.
27
+ * This is the name of the link between the service and the Secret Store, not
28
+ * the name of the Secret Store. The default is 'S3_CREDENTIALS'.
29
+ */
30
+ export function setSecretStoreForS3Credentials(resourceLinkName) {
31
+ _secretStoreLinkNameForS3Credentials = resourceLinkName;
27
32
  }
28
33
  export function setSecretStoreKeyForS3AccessKeyId(secretStoreKey) {
29
34
  _secretStoreKeyForS3AccessKeyId = secretStoreKey;
@@ -38,19 +43,19 @@ export async function buildS3CredentialsFromSecretStore() {
38
43
  }
39
44
  let secretStore;
40
45
  try {
41
- secretStore = new SecretStore(_secretStoreForS3Credentials);
46
+ secretStore = new SecretStore(_secretStoreLinkNameForS3Credentials);
42
47
  }
43
48
  catch {
44
- throw new Error(`Could not open secret store for S3 credentials: ${_secretStoreForS3Credentials}`);
49
+ throw new Error(`Could not open the secret store for S3 credentials with the resource link name '${_secretStoreLinkNameForS3Credentials}'`);
45
50
  }
46
51
  const accessKeyIdEntry = await secretStore.get(_secretStoreKeyForS3AccessKeyId);
47
52
  if (accessKeyIdEntry == null) {
48
- throw new Error(`Could not retrieve value '${_secretStoreKeyForS3AccessKeyId}' in secret store '${_secretStoreForS3Credentials}'`);
53
+ throw new Error(`Could not retrieve value '${_secretStoreKeyForS3AccessKeyId}' in the secret store with the resource link name '${_secretStoreLinkNameForS3Credentials}'`);
49
54
  }
50
55
  const accessKeyId = accessKeyIdEntry.plaintext();
51
56
  const secretAccessKeyEntry = await secretStore.get(_secretStoreKeyForS3SecretAccessKey);
52
57
  if (secretAccessKeyEntry == null) {
53
- throw new Error(`Could not retrieve value '${_secretStoreKeyForS3SecretAccessKey}' in secret store '${_secretStoreForS3Credentials}'`);
58
+ throw new Error(`Could not retrieve value '${_secretStoreKeyForS3SecretAccessKey}' in the secret store with the resource link name '${_secretStoreLinkNameForS3Credentials}'`);
54
59
  }
55
60
  const secretAccessKey = secretAccessKeyEntry.plaintext();
56
61
  _s3CredentialsFromSecretStore = {
@@ -0,0 +1,5 @@
1
+ export declare class BodyLengthError extends Error {
2
+ constructor(description: string, expectedLength: number, actualLength: number, complete: boolean);
3
+ }
4
+ export declare function checkBodyLength(body: ReadableStream<Uint8Array>, expectedLength: number, description: string): Promise<ReadableStream<Uint8Array>>;
5
+ //# sourceMappingURL=body-length.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-length.d.ts","sourceRoot":"","sources":["../../../../src/server/util/body-length.ts"],"names":[],"mappings":"AAQA,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO;CAIjG;AAaD,wBAAsB,eAAe,CACnC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAyCrC"}
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ // A stored body that does not have the size that its metadata gives. Storage can
6
+ // return such a body for a short time, for example a KV Store entry whose
7
+ // metadata reached the POP before its body.
8
+ export class BodyLengthError extends Error {
9
+ constructor(description, expectedLength, actualLength, complete) {
10
+ super(`${description}: expected ${expectedLength} bytes, got ${complete ? '' : 'at least '}${actualLength}`);
11
+ this.name = 'BodyLengthError';
12
+ }
13
+ }
14
+ // The runtime does not log the message of an error from the request handler or
15
+ // from a response body stream. Thus log the error here.
16
+ function logged(err) {
17
+ console.error(err.message);
18
+ return err;
19
+ }
20
+ // Returns a stream with the bytes of body. The stream errors with a
21
+ // BodyLengthError if body has a different number of bytes than expectedLength.
22
+ // This function reads the first chunk before it returns, so it throws for an
23
+ // empty body before a response is made from the stream.
24
+ export async function checkBodyLength(body, expectedLength, description) {
25
+ const reader = body.getReader();
26
+ const first = await reader.read();
27
+ let length = first.done ? 0 : first.value.byteLength;
28
+ if ((first.done && expectedLength !== 0) || length > expectedLength) {
29
+ await reader.cancel();
30
+ throw logged(new BodyLengthError(description, expectedLength, length, first.done));
31
+ }
32
+ let firstChunk = first.done ? null : first.value;
33
+ let done = first.done;
34
+ return new ReadableStream({
35
+ async pull(controller) {
36
+ if (firstChunk != null) {
37
+ controller.enqueue(firstChunk);
38
+ firstChunk = null;
39
+ return;
40
+ }
41
+ const result = done ? { done: true } : await reader.read();
42
+ if (!result.done) {
43
+ length += result.value.byteLength;
44
+ if (length > expectedLength) {
45
+ await reader.cancel();
46
+ controller.error(logged(new BodyLengthError(description, expectedLength, length, false)));
47
+ return;
48
+ }
49
+ controller.enqueue(result.value);
50
+ return;
51
+ }
52
+ done = true;
53
+ if (length !== expectedLength) {
54
+ controller.error(logged(new BodyLengthError(description, expectedLength, length, true)));
55
+ return;
56
+ }
57
+ controller.close();
58
+ },
59
+ async cancel(reason) {
60
+ await reader.cancel(reason);
61
+ },
62
+ });
63
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "8.0.0-rc.1",
4
+ "version": "8.0.0",
5
5
  "description": "Static Publisher for Fastly Compute JavaScript",
6
- "main": "build/index.js",
6
+ "main": "build/server/server/index.js",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./build/server/server/index.d.ts",
@@ -46,7 +46,7 @@
46
46
  "@smithy/signature-v4": "^5.7.4",
47
47
  "command-line-args": "^5.2.1",
48
48
  "glob-to-regexp": "^0.4.1",
49
- "toml": "^5.0.0"
49
+ "toml": "^5.0.1"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@fastly/js-compute": "^3.33.2 || ^4.0.0"