@fastly/compute-js-static-publish 8.0.0-beta.18 → 8.0.0-beta.19
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.
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +2 -1
- package/build/cli/cli/util/content-types.js +1 -1
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +9 -2
- package/build/server/server/storage/s3-storage-provider.d.ts +2 -5
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.js +95 -38
- package/build/server/server/storage/storage-provider.d.ts +1 -1
- package/build/server/server/storage/storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/storage-provider.js +2 -1
- package/package.json +9 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAQA,OAAO,EAUL,QAAQ,EAIT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AASxB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAa/B,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAKnF,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,eAAO,MAAM,kBAAkB,EAAE,sBAqChC,CAAC;AAGF,qBAAa,iBAAkB,YAAW,eAAe;gBAErD,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE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AG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAaV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BvF,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,EAC1B,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAmBhB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAI1C"}
|
|
@@ -101,7 +101,8 @@ export class S3StorageProvider {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
// An empty list is a valid result. The callers use null only for an error.
|
|
105
|
+
return objectKeys;
|
|
105
106
|
}
|
|
106
107
|
async getStorageEntry(key) {
|
|
107
108
|
const input = {
|
|
@@ -52,7 +52,7 @@ export function mergeContentTypes(contentTypes) {
|
|
|
52
52
|
invalid = true;
|
|
53
53
|
}
|
|
54
54
|
if (typeof contentType.contentType !== 'string' || contentType.contentType.indexOf('/') === -1) {
|
|
55
|
-
console.log(`⚠️ Ignoring contentTypes[${index}]: '
|
|
55
|
+
console.log(`⚠️ Ignoring contentTypes[${index}]: 'contentType' must be a string representing a MIME type.`);
|
|
56
56
|
invalid = true;
|
|
57
57
|
}
|
|
58
58
|
if ('text' in contentType && typeof contentType.text !== 'boolean') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-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U,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IA4DpF,WAAW,CACf,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GACtD,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;YAiFb,eAAe;IAoB7B,OAAO,CAAC,iBAAiB;IAwBnB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;YAsBhD,uBAAuB;CAwDtC"}
|
|
@@ -458,8 +458,15 @@ export class PublisherServer {
|
|
|
458
458
|
userMetadata: encodeCachedResponseMetadata(metadata),
|
|
459
459
|
length: Number.isInteger(contentLength) && headers.has('Content-Length') ? contentLength : undefined,
|
|
460
460
|
});
|
|
461
|
-
|
|
462
|
-
|
|
461
|
+
const copied = this.copyBodyToCache(response, writer);
|
|
462
|
+
const cachedResponse = this.responseFromCache(request, metadata, streamedEntry.body());
|
|
463
|
+
// A response without a body (HEAD, 304) does not keep the request running
|
|
464
|
+
// until the copy finishes. If the copy is cut short, the entry can be stored
|
|
465
|
+
// with a partial body, so wait for it.
|
|
466
|
+
if (cachedResponse?.body == null) {
|
|
467
|
+
await copied;
|
|
468
|
+
}
|
|
469
|
+
return cachedResponse;
|
|
463
470
|
}
|
|
464
471
|
async copyBodyToCache(response, writer) {
|
|
465
472
|
try {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Command } from '@smithy/types';
|
|
2
|
-
import { S3ClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from '@aws-sdk/client-s3';
|
|
3
1
|
import { type StorageEntry, type StorageProvider, StorageProviderBuilder } from './storage-provider.js';
|
|
4
2
|
export type S3Credentials = {
|
|
5
3
|
accessKeyId: string;
|
|
@@ -16,15 +14,14 @@ export type S3StorageProviderParams = {
|
|
|
16
14
|
s3Endpoint?: string;
|
|
17
15
|
s3FastlyBackendName?: string;
|
|
18
16
|
};
|
|
19
|
-
type S3ClientCommand<InputType extends ServiceInputTypes, OutputType extends ServiceOutputTypes> = Command<ServiceInputTypes, InputType, ServiceOutputTypes, OutputType, S3ClientResolvedConfig>;
|
|
20
17
|
export declare class S3StorageProvider implements StorageProvider {
|
|
21
18
|
constructor(s3Region: string, s3Bucket: string, params?: S3StorageProviderParams);
|
|
22
19
|
private readonly s3Region;
|
|
23
20
|
private readonly s3Bucket;
|
|
24
21
|
private readonly s3Endpoint?;
|
|
25
22
|
private readonly s3FastlyBackendName?;
|
|
26
|
-
|
|
23
|
+
objectUrl(key: string): URL;
|
|
24
|
+
fetchObject(key: string, requestInit: RequestInit): Promise<Response>;
|
|
27
25
|
getEntry(key: string, tags?: string[]): Promise<StorageEntry | null>;
|
|
28
26
|
}
|
|
29
|
-
export {};
|
|
30
27
|
//# sourceMappingURL=s3-storage-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/server/storage/s3-storage-provider.ts"],"names":[],"mappings":"
|
|
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,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"}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { CacheOverride } from 'fastly:cache-override';
|
|
6
6
|
import { SecretStore } from 'fastly:secret-store';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { Sha256 } from '@aws-crypto/sha256-js';
|
|
8
|
+
import { SignatureV4 } from '@smithy/signature-v4';
|
|
9
9
|
import { isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
10
10
|
import { getS3StorageConfigFromRc, } from '../../models/config/s3-storage-config.js';
|
|
11
11
|
import { concatReadableStreams, StorageEntryImpl, } from './storage-provider.js';
|
|
@@ -63,6 +63,21 @@ let _s3CredentialsBuilder = buildS3CredentialsFromSecretStore;
|
|
|
63
63
|
export function setS3CredentialsBuilder(s3CredentialsBuilder) {
|
|
64
64
|
_s3CredentialsBuilder = s3CredentialsBuilder;
|
|
65
65
|
}
|
|
66
|
+
// Attempts for a request that fails with a retryable status or a network error.
|
|
67
|
+
const MAX_ATTEMPTS = 5;
|
|
68
|
+
const RETRY_BASE_DELAY_MS = 100;
|
|
69
|
+
// Status codes that S3 asks clients to retry.
|
|
70
|
+
const RETRYABLE_STATUS_CODES = [429, 500, 502, 503, 504];
|
|
71
|
+
// The S3 key as a URL path. Like the AWS SDK, this also escapes !'()*.
|
|
72
|
+
function encodeS3Key(key) {
|
|
73
|
+
return key.split('/').map(segment => encodeURIComponent(segment).replace(/[!'()*]/g, c => '%' + c.charCodeAt(0).toString(16).toUpperCase())).join('/');
|
|
74
|
+
}
|
|
75
|
+
// The error code and message from an S3 XML error body, for the error message.
|
|
76
|
+
function describeS3Error(status, bodyText) {
|
|
77
|
+
const code = /<Code>([^<]*)<\/Code>/.exec(bodyText)?.[1];
|
|
78
|
+
const message = /<Message>([^<]*)<\/Message>/.exec(bodyText)?.[1];
|
|
79
|
+
return [`S3 GetObject failed with status ${status}`, code, message].filter(Boolean).join(': ');
|
|
80
|
+
}
|
|
66
81
|
export class S3StorageProvider {
|
|
67
82
|
constructor(s3Region, s3Bucket, params) {
|
|
68
83
|
this.s3Region = s3Region;
|
|
@@ -70,55 +85,97 @@ export class S3StorageProvider {
|
|
|
70
85
|
this.s3Endpoint = params?.s3Endpoint;
|
|
71
86
|
this.s3FastlyBackendName = params?.s3FastlyBackendName;
|
|
72
87
|
}
|
|
73
|
-
|
|
88
|
+
// The URL of an object. With a custom endpoint, such as Fastly Object Storage,
|
|
89
|
+
// the bucket is in the path. Otherwise, it is in the AWS host name.
|
|
90
|
+
objectUrl(key) {
|
|
91
|
+
if (this.s3Endpoint != null) {
|
|
92
|
+
const url = new URL(this.s3Endpoint);
|
|
93
|
+
url.pathname = url.pathname.replace(/\/$/, '') + '/' + encodeURIComponent(this.s3Bucket) + '/' + encodeS3Key(key);
|
|
94
|
+
return url;
|
|
95
|
+
}
|
|
96
|
+
return new URL(`https://${this.s3Bucket}.s3.${this.s3Region}.amazonaws.com/${encodeS3Key(key)}`);
|
|
97
|
+
}
|
|
98
|
+
// Sends a signed GET request for an object. The AWS SDK is not used here: its
|
|
99
|
+
// browser build, which js-compute bundles, parses XML with DOMParser, which
|
|
100
|
+
// Compute does not have.
|
|
101
|
+
async fetchObject(key, requestInit) {
|
|
74
102
|
const s3Credentials = await _s3CredentialsBuilder();
|
|
75
|
-
const
|
|
103
|
+
const signer = new SignatureV4({
|
|
104
|
+
service: 's3',
|
|
76
105
|
region: this.s3Region,
|
|
77
|
-
endpoint: this.s3Endpoint,
|
|
78
|
-
forcePathStyle: this.s3Endpoint != null,
|
|
79
106
|
credentials: {
|
|
80
107
|
accessKeyId: s3Credentials.accessKeyId,
|
|
81
108
|
secretAccessKey: s3Credentials.secretAccessKey,
|
|
82
109
|
},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return requestInit ?? {};
|
|
87
|
-
},
|
|
88
|
-
}),
|
|
110
|
+
sha256: Sha256,
|
|
111
|
+
// The path is already escaped by encodeS3Key(). S3 expects it escaped once.
|
|
112
|
+
uriEscapePath: false,
|
|
89
113
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
cacheOverride: new CacheOverride({
|
|
103
|
-
ttl: 3600,
|
|
104
|
-
surrogateKey: (tags ?? []).join(' ') || undefined,
|
|
105
|
-
}),
|
|
114
|
+
const url = this.objectUrl(key);
|
|
115
|
+
for (let attempt = 1;; attempt++) {
|
|
116
|
+
const signed = await signer.sign({
|
|
117
|
+
method: 'GET',
|
|
118
|
+
protocol: url.protocol,
|
|
119
|
+
hostname: url.hostname,
|
|
120
|
+
port: url.port !== '' ? Number(url.port) : undefined,
|
|
121
|
+
path: url.pathname,
|
|
122
|
+
headers: {
|
|
123
|
+
host: url.host,
|
|
124
|
+
'x-amz-content-sha256': 'UNSIGNED-PAYLOAD',
|
|
125
|
+
},
|
|
106
126
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
127
|
+
let response = null;
|
|
128
|
+
let error = null;
|
|
129
|
+
try {
|
|
130
|
+
response = await fetch(url, {
|
|
131
|
+
...requestInit,
|
|
132
|
+
method: 'GET',
|
|
133
|
+
headers: signed.headers,
|
|
134
|
+
});
|
|
112
135
|
}
|
|
113
|
-
|
|
114
|
-
|
|
136
|
+
catch (err) {
|
|
137
|
+
error = err;
|
|
115
138
|
}
|
|
139
|
+
const retryable = response == null || RETRYABLE_STATUS_CODES.includes(response.status);
|
|
140
|
+
if (!retryable || attempt >= MAX_ATTEMPTS) {
|
|
141
|
+
if (response == null) {
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
return response;
|
|
145
|
+
}
|
|
146
|
+
// Exponential backoff with jitter.
|
|
147
|
+
const delay = Math.random() * RETRY_BASE_DELAY_MS * 2 ** (attempt - 1);
|
|
148
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async getEntry(key, tags) {
|
|
152
|
+
const response = await this.fetchObject(key, {
|
|
153
|
+
backend: this.s3FastlyBackendName ?? "s3_storage",
|
|
154
|
+
cacheOverride: new CacheOverride({
|
|
155
|
+
ttl: 3600,
|
|
156
|
+
surrogateKey: (tags ?? []).join(' ') || undefined,
|
|
157
|
+
}),
|
|
158
|
+
});
|
|
159
|
+
if (response.status === 404) {
|
|
160
|
+
console.log("Object does not exist");
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
if (!response.ok) {
|
|
164
|
+
// some other problem (auth, etc.)
|
|
165
|
+
throw new Error(describeS3Error(response.status, await response.text()));
|
|
116
166
|
}
|
|
117
|
-
if (response.
|
|
167
|
+
if (response.body == null) {
|
|
118
168
|
return null;
|
|
119
169
|
}
|
|
120
|
-
|
|
121
|
-
const
|
|
170
|
+
// User-defined object metadata comes in x-amz-meta-* headers.
|
|
171
|
+
const metadata = {};
|
|
172
|
+
for (const [name, value] of response.headers.entries()) {
|
|
173
|
+
if (name.startsWith('x-amz-meta-')) {
|
|
174
|
+
metadata[name.slice('x-amz-meta-'.length)] = value;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const body = concatReadableStreams([response.body]);
|
|
178
|
+
const metadataText = JSON.stringify(metadata);
|
|
122
179
|
return new StorageEntryImpl(body, metadataText);
|
|
123
180
|
}
|
|
124
181
|
}
|
|
@@ -38,7 +38,7 @@ export interface StorageEntry {
|
|
|
38
38
|
export declare class StorageEntryImpl extends Response implements StorageEntry {
|
|
39
39
|
constructor(body: BodyInit, metadataText: string);
|
|
40
40
|
private readonly metadataTextValue;
|
|
41
|
-
get body(): ReadableStream<Uint8Array
|
|
41
|
+
get body(): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
42
42
|
metadata(): ArrayBuffer | null;
|
|
43
43
|
metadataText(): string | null;
|
|
44
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/server/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAElD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;CACtE;AAED,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AAM,CAAC,CAAC;IAExB;;OAEG;IACH,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAExB;;OAEG;IACH,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAEpC;;OAEG;IACH,QAAQ,IAAI,WAAW,GAAG,IAAI,CAAC;IAE/B;;;OAGG;IACH,YAAY,IAAI,MAAM,GAAG,IAAI,CAAC;CAC/B;AAKD,qBAAa,gBAAiB,SAAQ,QAAS,YAAW,YAAY;gBACxD,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM;IAKhD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAE3C,IAAI,IAAI,4CAEP;IAED,QAAQ,IAAI,WAAW,GAAG,IAAI;IAG9B,YAAY,IAAI,MAAM,GAAG,IAAI;CAG9B;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,EAAE,GAAG,cAAc,CAAC,UAAU,CAAC,CAuCvG;AAGD,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,QAE7E;AAED,wBAAgB,sCAAsC,CAAC,MAAM,EAAE,eAAe,mBAS7E"}
|
|
@@ -10,11 +10,12 @@ export class StorageEntryImpl extends Response {
|
|
|
10
10
|
super(body);
|
|
11
11
|
this.metadataTextValue = metadataText;
|
|
12
12
|
}
|
|
13
|
+
// The type of Response.body differs between @fastly/js-compute 3 and 4, so it is inferred.
|
|
13
14
|
get body() {
|
|
14
15
|
return super.body;
|
|
15
16
|
}
|
|
16
17
|
metadata() {
|
|
17
|
-
return new TextEncoder().encode(this.metadataTextValue);
|
|
18
|
+
return new TextEncoder().encode(this.metadataTextValue).buffer;
|
|
18
19
|
}
|
|
19
20
|
metadataText() {
|
|
20
21
|
return this.metadataTextValue;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastly/compute-js-static-publish",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "8.0.0-beta.
|
|
4
|
+
"version": "8.0.0-beta.19",
|
|
5
5
|
"description": "Static Publisher for Fastly Compute JavaScript",
|
|
6
6
|
"main": "build/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"compile": "npm run compile:cli && npm run compile:server",
|
|
18
18
|
"compile:cli": "tsc -p tsconfig.cli.json",
|
|
19
19
|
"compile:server": "tsc -p tsconfig.server.json",
|
|
20
|
-
"test": "
|
|
20
|
+
"test": "npm run build && node --test \"test/unit/*.test.js\"",
|
|
21
|
+
"test:e2e": "npm run build && node --test --test-concurrency=1 \"test/e2e/*.test.js\"",
|
|
21
22
|
"prepublishOnly": "cp README.short.md README.md"
|
|
22
23
|
},
|
|
23
24
|
"bin": {
|
|
@@ -40,16 +41,18 @@
|
|
|
40
41
|
},
|
|
41
42
|
"homepage": "https://github.com/fastly/compute-js-static-publish#readme",
|
|
42
43
|
"dependencies": {
|
|
43
|
-
"@aws-
|
|
44
|
+
"@aws-crypto/sha256-js": "^5.2.0",
|
|
45
|
+
"@aws-sdk/client-s3": "^3.1147.0",
|
|
46
|
+
"@smithy/signature-v4": "^5.7.4",
|
|
44
47
|
"command-line-args": "^5.2.1",
|
|
45
48
|
"glob-to-regexp": "^0.4.1",
|
|
46
|
-
"toml": "^
|
|
49
|
+
"toml": "^5.0.0"
|
|
47
50
|
},
|
|
48
51
|
"peerDependencies": {
|
|
49
|
-
"@fastly/js-compute": "^3.33.2"
|
|
52
|
+
"@fastly/js-compute": "^3.33.2 || ^4.0.0"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
52
|
-
"@fastly/js-compute": "^
|
|
55
|
+
"@fastly/js-compute": "^4.0.0",
|
|
53
56
|
"@types/command-line-args": "^5.2.0",
|
|
54
57
|
"@types/glob-to-regexp": "^0.4.1",
|
|
55
58
|
"@types/node": "^20.11.0",
|