@fastly/compute-js-static-publish 8.0.0-beta.13 → 8.0.0-beta.15
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/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +2 -3
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +2 -3
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +2 -3
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +2 -3
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +2 -3
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +2 -3
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +2 -3
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +10 -3
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +9 -6
- package/build/cli/cli/storage/storage-provider.d.ts +1 -0
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/util/api-token.d.ts.map +1 -1
- package/build/cli/cli/util/api-token.js +0 -28
- package/build/cli/cli/util/service-id.d.ts +10 -0
- package/build/cli/cli/util/service-id.d.ts.map +1 -0
- package/build/cli/cli/util/service-id.js +26 -0
- package/build/server/server/publisher-server/index.d.ts +6 -0
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +35 -12
- package/build/server/server/util/server-timing.d.ts +7 -0
- package/build/server/server/util/server-timing.d.ts.map +1 -0
- package/build/server/server/util/server-timing.js +34 -0
- package/package.json +1 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"AAmDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}
|
|
@@ -29,9 +29,8 @@ KV Store Options:
|
|
|
29
29
|
with the local development environment.
|
|
30
30
|
|
|
31
31
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
32
|
-
If not set, the tool
|
|
33
|
-
|
|
34
|
-
2. The default profile in the Fastly CLI
|
|
32
|
+
If not set, the tool uses the FASTLY_API_TOKEN
|
|
33
|
+
environment variable.
|
|
35
34
|
|
|
36
35
|
S3 Storage Options (BETA):
|
|
37
36
|
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAiDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuIhD"}
|
|
@@ -28,9 +28,8 @@ KV Store Options:
|
|
|
28
28
|
with the local development environment.
|
|
29
29
|
|
|
30
30
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
31
|
-
If not set, the tool
|
|
32
|
-
|
|
33
|
-
2. The default profile in the Fastly CLI
|
|
31
|
+
If not set, the tool uses the FASTLY_API_TOKEN
|
|
32
|
+
environment variable.
|
|
34
33
|
|
|
35
34
|
S3 Storage Options (BETA):
|
|
36
35
|
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"AAmDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0BhD"}
|
|
@@ -29,9 +29,8 @@ KV Store Options:
|
|
|
29
29
|
with the local development environment.
|
|
30
30
|
|
|
31
31
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
32
|
-
If not set, the tool
|
|
33
|
-
|
|
34
|
-
2. The default profile in the Fastly CLI
|
|
32
|
+
If not set, the tool uses the FASTLY_API_TOKEN
|
|
33
|
+
environment variable.
|
|
35
34
|
|
|
36
35
|
S3 Storage Options (BETA):
|
|
37
36
|
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"AA4CA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAmIhD"}
|
|
@@ -23,9 +23,8 @@ KV Store Options:
|
|
|
23
23
|
with the local development environment.
|
|
24
24
|
|
|
25
25
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
26
|
-
If not set, the tool
|
|
27
|
-
|
|
28
|
-
2. The default profile in the Fastly CLI
|
|
26
|
+
If not set, the tool uses the FASTLY_API_TOKEN
|
|
27
|
+
environment variable.
|
|
29
28
|
|
|
30
29
|
S3 Storage Options (BETA):
|
|
31
30
|
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AAkEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuLhD"}
|
|
@@ -45,9 +45,8 @@ KV Store Options:
|
|
|
45
45
|
with the local development environment.
|
|
46
46
|
|
|
47
47
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
48
|
-
If not set, the tool
|
|
49
|
-
|
|
50
|
-
2. The default profile in the Fastly CLI
|
|
48
|
+
If not set, the tool uses the FASTLY_API_TOKEN
|
|
49
|
+
environment variable.
|
|
51
50
|
|
|
52
51
|
S3 Storage Options (BETA):
|
|
53
52
|
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"AA8DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0JhD"}
|
|
@@ -41,9 +41,8 @@ KV Store Options:
|
|
|
41
41
|
with the local development environment.
|
|
42
42
|
|
|
43
43
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
44
|
-
If not set, the tool
|
|
45
|
-
|
|
46
|
-
2. The default profile in the Fastly CLI
|
|
44
|
+
If not set, the tool uses the FASTLY_API_TOKEN
|
|
45
|
+
environment variable.
|
|
47
46
|
|
|
48
47
|
S3 Storage Options (BETA):
|
|
49
48
|
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"AA0DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyBhD"}
|
|
@@ -31,9 +31,8 @@ KV Store Options:
|
|
|
31
31
|
with the local development environment.
|
|
32
32
|
|
|
33
33
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
34
|
-
If not set, the tool
|
|
35
|
-
|
|
36
|
-
2. The default profile in the Fastly CLI
|
|
34
|
+
If not set, the tool uses the FASTLY_API_TOKEN
|
|
35
|
+
environment variable.
|
|
37
36
|
|
|
38
37
|
S3 Storage Options (BETA):
|
|
39
38
|
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AAoHA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAoiBhD"}
|
|
@@ -44,9 +44,14 @@ Optional:
|
|
|
44
44
|
Default: rootDir from publish-content.config.js
|
|
45
45
|
|
|
46
46
|
--fastly-api-token=<token> Fastly API token for KV Store or cache access.
|
|
47
|
+
If not set, the tool uses the FASTLY_API_TOKEN
|
|
48
|
+
environment variable.
|
|
49
|
+
|
|
50
|
+
--fastly-service-id=<id> Fastly Service ID to purge after publishing (S3 storage).
|
|
47
51
|
If not set, the tool will check:
|
|
48
|
-
1.
|
|
49
|
-
2.
|
|
52
|
+
1. service_id in fastly.toml
|
|
53
|
+
2. FASTLY_SERVICE_ID environment variable
|
|
54
|
+
If none is found, the purge is skipped.
|
|
50
55
|
|
|
51
56
|
--overwrite-existing Always overwrite existing entries in storage, even if unchanged.
|
|
52
57
|
|
|
@@ -105,6 +110,7 @@ export async function action(actionArgs) {
|
|
|
105
110
|
{ name: 'expires-never', type: Boolean },
|
|
106
111
|
{ name: 'local', type: Boolean },
|
|
107
112
|
{ name: 'fastly-api-token', type: String, },
|
|
113
|
+
{ name: 'fastly-service-id', type: String, },
|
|
108
114
|
{ name: 'kv-overwrite', type: Boolean },
|
|
109
115
|
{ name: 's3-access-key-id', type: String, },
|
|
110
116
|
{ name: 's3-secret-access-key', type: String, },
|
|
@@ -120,7 +126,7 @@ export async function action(actionArgs) {
|
|
|
120
126
|
help();
|
|
121
127
|
return;
|
|
122
128
|
}
|
|
123
|
-
const { verbose, config: configFilePathValue, ['collection-name']: collectionNameValue, ['root-dir']: rootDir, ['overwrite-existing']: _overwriteExisting, ['brotli-quality']: brotliQualityValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['kv-overwrite']: _kvOverwrite, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, ['s3-upload-concurrency']: s3UploadConcurrencyValue, } = parsed.commandLineOptions;
|
|
129
|
+
const { verbose, config: configFilePathValue, ['collection-name']: collectionNameValue, ['root-dir']: rootDir, ['overwrite-existing']: _overwriteExisting, ['brotli-quality']: brotliQualityValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['fastly-service-id']: fastlyServiceId, ['kv-overwrite']: _kvOverwrite, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, ['s3-upload-concurrency']: s3UploadConcurrencyValue, } = parsed.commandLineOptions;
|
|
124
130
|
let s3UploadConcurrency;
|
|
125
131
|
if (s3UploadConcurrencyValue !== undefined) {
|
|
126
132
|
if (typeof s3UploadConcurrencyValue !== 'string' || !/^\d+$/.test(s3UploadConcurrencyValue) ||
|
|
@@ -213,6 +219,7 @@ export async function action(actionArgs) {
|
|
|
213
219
|
computeAppDir,
|
|
214
220
|
localMode,
|
|
215
221
|
fastlyApiToken,
|
|
222
|
+
fastlyServiceId,
|
|
216
223
|
s3AccessKeyId,
|
|
217
224
|
s3SecretAccessKey,
|
|
218
225
|
s3UploadConcurrency,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AASA,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;AAuB/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,
|
|
1
|
+
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AASA,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;AAuB/B,KAAK,aAAa,CA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CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IA6B1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAwB9D,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,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;IA+BvF,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;IAInC,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA4B7D"}
|
|
@@ -14,7 +14,7 @@ import { loadS3Credentials, } from '../util/s3-credentials.js';
|
|
|
14
14
|
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
15
15
|
import { rootRelative, } from '../util/files.js';
|
|
16
16
|
import { loadApiToken, } from '../util/api-token.js';
|
|
17
|
-
import {
|
|
17
|
+
import { loadServiceId, } from '../util/service-id.js';
|
|
18
18
|
import { purgeSurrogateKey, } from '../util/purge.js';
|
|
19
19
|
// The number of objects to upload at the same time. S3 accepts many parallel
|
|
20
20
|
// requests, and each request mostly waits for the network. In a test with small
|
|
@@ -40,14 +40,17 @@ export const buildStoreProvider = async (config, context) => {
|
|
|
40
40
|
throw new Error("❌ S3 Credentials not provided.\nProvide an access key ID and secret access key that have write access to the S3 or compatible storage.\nRefer to the README file and --help for additional information.");
|
|
41
41
|
}
|
|
42
42
|
console.log(`✔️ S3 Credentials: ${s3CredentialsResult.s3AccessKeyId.slice(0, 4)}${'*'.repeat(s3CredentialsResult.s3AccessKeyId.length - 4)} from '${s3CredentialsResult.source}'`);
|
|
43
|
-
const
|
|
44
|
-
|
|
43
|
+
const serviceIdResult = loadServiceId({
|
|
44
|
+
commandLine: context.fastlyServiceId,
|
|
45
|
+
fastlyTomlPath: path.resolve(context.computeAppDir, 'fastly.toml'),
|
|
46
|
+
});
|
|
47
|
+
const serviceId = serviceIdResult?.serviceId;
|
|
45
48
|
let apiToken = undefined;
|
|
46
|
-
if (
|
|
47
|
-
console.log(`- Service ID not found
|
|
49
|
+
if (serviceIdResult == null) {
|
|
50
|
+
console.log(`- Service ID not found (--fastly-service-id, fastly.toml, or FASTLY_SERVICE_ID). Will skip purge step after publish.`);
|
|
48
51
|
}
|
|
49
52
|
else {
|
|
50
|
-
console.log(`✔️ Service ID from
|
|
53
|
+
console.log(`✔️ Service ID from ${serviceIdResult.source}: ${serviceIdResult.serviceId}`);
|
|
51
54
|
const apiTokenResult = loadApiToken({ commandLine: context.fastlyApiToken });
|
|
52
55
|
if (apiTokenResult == null) {
|
|
53
56
|
throw new Error("❌ Fastly API Token not provided.\nSet the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,eAAe,EAC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AE,MAAM,CAAC,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAG9B,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC5B,CAAC;AAEF,qBAAa,oBAAoB;;IAI/B,2BAA2B,EAAE,yBAAyB,EAAE,CAAC;IACzD,GAAG,CAAC,KAAK,EAAE,yBAAyB;CAGrC;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AACF,MAAM,MAAM,sBAAsB,GAChC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,KAAK,CAAC,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC,CAAC;AAQlI,wBAAsB,yBAAyB,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAQ1H;AAGD,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,QAE7E;AAED,wBAAsB,sCAAsC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,4BAS3H"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAyB7E;AAaD,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK3C,MAAM,EAAE,MAAM,CAAC;CAChB;AAWD,wBAAsB,aAAa,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,eAAe,GAAG,IAAI,EACpC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,QAAQ,CAAC,CAqCnB"}
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
import { spawnSync } from 'node:child_process';
|
|
6
|
-
import cli from '@fastly/cli';
|
|
7
5
|
import { makeRetryable } from './retryable.js';
|
|
8
6
|
export function loadApiToken(params) {
|
|
9
7
|
let apiToken = null;
|
|
@@ -20,32 +18,6 @@ export function loadApiToken(params) {
|
|
|
20
18
|
source = 'env';
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
|
-
// Try fastly cli
|
|
24
|
-
if (apiToken == null) {
|
|
25
|
-
try {
|
|
26
|
-
const { stdout, error, status } = spawnSync(cli, ['profile', 'token', '--quiet'], {
|
|
27
|
-
encoding: 'utf-8',
|
|
28
|
-
});
|
|
29
|
-
if (status != null && status !== 0) {
|
|
30
|
-
console.warn(`⚠️ Warning: 'fastly profile token' returned a non-zero status code.`);
|
|
31
|
-
apiToken = null;
|
|
32
|
-
}
|
|
33
|
-
else if (error) {
|
|
34
|
-
console.warn(`⚠️ Warning: 'fastly profile token' returned an error:`);
|
|
35
|
-
console.warn(String(error));
|
|
36
|
-
apiToken = null;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
apiToken = stdout.trim();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
apiToken = null;
|
|
44
|
-
}
|
|
45
|
-
if (apiToken != null) {
|
|
46
|
-
source = 'fastly-profile-token';
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
21
|
if (apiToken == null) {
|
|
50
22
|
return null;
|
|
51
23
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type LoadServiceIdResult = {
|
|
2
|
+
serviceId: string;
|
|
3
|
+
source: string;
|
|
4
|
+
};
|
|
5
|
+
export type LoadServiceIdParams = {
|
|
6
|
+
commandLine: unknown;
|
|
7
|
+
fastlyTomlPath: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function loadServiceId(params: LoadServiceIdParams): LoadServiceIdResult | null;
|
|
10
|
+
//# sourceMappingURL=service-id.d.ts.map
|
|
@@ -0,0 +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;AAMF,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,GAAG,IAAI,CAmBrF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import { readServiceId } from './fastly-toml.js';
|
|
7
|
+
// Finds the Fastly Service ID to purge after publishing. Checks, in order:
|
|
8
|
+
// 1. The command line (--fastly-service-id)
|
|
9
|
+
// 2. service_id in fastly.toml
|
|
10
|
+
// 3. The FASTLY_SERVICE_ID environment variable
|
|
11
|
+
export function loadServiceId(params) {
|
|
12
|
+
if (typeof params.commandLine === 'string' && params.commandLine.trim() !== '') {
|
|
13
|
+
return { serviceId: params.commandLine.trim(), source: 'commandline' };
|
|
14
|
+
}
|
|
15
|
+
if (fs.existsSync(params.fastlyTomlPath)) {
|
|
16
|
+
const serviceId = readServiceId(params.fastlyTomlPath);
|
|
17
|
+
if (serviceId != null) {
|
|
18
|
+
return { serviceId, source: 'fastly.toml' };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const envServiceId = process.env.FASTLY_SERVICE_ID?.trim();
|
|
22
|
+
if (envServiceId) {
|
|
23
|
+
return { serviceId: envServiceId, source: 'env' };
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
@@ -3,6 +3,7 @@ import { type PublisherServerConfigNormalized } from '../../models/config/publis
|
|
|
3
3
|
import { type ContentCompressionTypes } from '../../models/compression/index.js';
|
|
4
4
|
import { type AssetEntry, type AssetEntryMap, type AssetVariantMetadata } from '../../models/assets/index.js';
|
|
5
5
|
import { type StorageEntry, type StorageProvider } from '../storage/storage-provider.js';
|
|
6
|
+
import { ServerTiming } from '../util/server-timing.js';
|
|
6
7
|
type AssetVariant = {
|
|
7
8
|
storageEntry: StorageEntry;
|
|
8
9
|
} & AssetVariantMetadata;
|
|
@@ -20,10 +21,15 @@ export declare class PublisherServer {
|
|
|
20
21
|
defaultCollectionName: string;
|
|
21
22
|
activeCollectionName: string;
|
|
22
23
|
collectionNameHeader: string | null;
|
|
24
|
+
serverTimingRequestHeader: string | null;
|
|
25
|
+
serverTiming: ServerTiming | null;
|
|
23
26
|
settingsCached: PublisherServerConfigNormalized | null | undefined;
|
|
24
27
|
assetEntryMapCache: AssetEntryMap | null | undefined;
|
|
25
28
|
setActiveCollectionName(collectionName: string): void;
|
|
26
29
|
setCollectionNameHeader(collectionHeader: string | null): void;
|
|
30
|
+
setServerTimingRequestHeader(requestHeader: string | null): void;
|
|
31
|
+
beginRequest(request: Request): void;
|
|
32
|
+
private timed;
|
|
27
33
|
getServerConfig(): Promise<PublisherServerConfigNormalized | null>;
|
|
28
34
|
getStaticItems(): Promise<(string | RegExp)[]>;
|
|
29
35
|
getAssetEntryMap(): Promise<AssetEntryMap | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,+BAA+B,EACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EAErB,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,+BAA+B,EACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EAErB,MA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B,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA2D1F,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC;IAoDjF,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAcxC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI;IA6DtF,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;YA8BzG,wCAAwC;IAyChD,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IAqDpF,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAuE/D"}
|
|
@@ -8,6 +8,7 @@ import { isExpired } from '../../models/time/index.js';
|
|
|
8
8
|
import { loadStorageProviderFromStaticPublishRc, } from '../storage/storage-provider.js';
|
|
9
9
|
import { checkIfModifiedSince, getIfModifiedSinceHeader } from './serve-preconditions/if-modified-since.js';
|
|
10
10
|
import { checkIfNoneMatch, getIfNoneMatchHeader } from './serve-preconditions/if-none-match.js';
|
|
11
|
+
import { ServerTiming } from '../util/server-timing.js';
|
|
11
12
|
export function buildHeadersSubset(responseHeaders, keys) {
|
|
12
13
|
const resultHeaders = new Headers();
|
|
13
14
|
for (const value of keys) {
|
|
@@ -42,6 +43,8 @@ export class PublisherServer {
|
|
|
42
43
|
this.defaultCollectionName = defaultCollectionName;
|
|
43
44
|
this.activeCollectionName = this.defaultCollectionName;
|
|
44
45
|
this.collectionNameHeader = 'X-Publisher-Server-Collection';
|
|
46
|
+
this.serverTimingRequestHeader = null;
|
|
47
|
+
this.serverTiming = null;
|
|
45
48
|
}
|
|
46
49
|
static fromStaticPublishRc(config) {
|
|
47
50
|
const storeProvider = loadStorageProviderFromStaticPublishRc(config);
|
|
@@ -55,21 +58,35 @@ export class PublisherServer {
|
|
|
55
58
|
setCollectionNameHeader(collectionHeader) {
|
|
56
59
|
this.collectionNameHeader = collectionHeader;
|
|
57
60
|
}
|
|
61
|
+
// Set the request header that turns on the Server-Timing response header.
|
|
62
|
+
// null (the default) turns timing off.
|
|
63
|
+
setServerTimingRequestHeader(requestHeader) {
|
|
64
|
+
this.serverTimingRequestHeader = requestHeader;
|
|
65
|
+
}
|
|
66
|
+
// Start handling a new request. serveRequest() calls this. If you call
|
|
67
|
+
// getMatchingAsset() and serveAsset() directly, call this first.
|
|
68
|
+
beginRequest(request) {
|
|
69
|
+
const header = this.serverTimingRequestHeader;
|
|
70
|
+
this.serverTiming = header != null && request.headers.has(header) ? new ServerTiming() : null;
|
|
71
|
+
}
|
|
72
|
+
timed(name, fn) {
|
|
73
|
+
return this.serverTiming != null ? this.serverTiming.measure(name, fn) : fn();
|
|
74
|
+
}
|
|
58
75
|
// Server config is obtained from storage, and cached for the duration of this object.
|
|
59
76
|
async getServerConfig() {
|
|
60
77
|
if (this.settingsCached !== undefined) {
|
|
61
78
|
return this.settingsCached;
|
|
62
79
|
}
|
|
63
80
|
const settingsFileKey = `${this.publishId}_settings_${this.activeCollectionName}`;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
81
|
+
this.settingsCached = await this.timed('settings', async () => {
|
|
82
|
+
const settingsFile = await this.storageProvider.getEntry(settingsFileKey, [`${this.publishId}-${this.activeCollectionName}`, 'settings']);
|
|
83
|
+
if (settingsFile == null) {
|
|
84
|
+
console.error(`Settings File not found at ${settingsFileKey}.`);
|
|
85
|
+
console.error(`You may need to publish your application.`);
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return (await settingsFile.json());
|
|
89
|
+
});
|
|
73
90
|
return this.settingsCached;
|
|
74
91
|
}
|
|
75
92
|
async getStaticItems() {
|
|
@@ -96,7 +113,7 @@ export class PublisherServer {
|
|
|
96
113
|
return this.assetEntryMapCache;
|
|
97
114
|
}
|
|
98
115
|
const indexFileKey = `${this.publishId}_index_${this.activeCollectionName}`;
|
|
99
|
-
const indexFile = await this.storageProvider.getEntry(indexFileKey, [`${this.publishId}-${this.activeCollectionName}`, 'index']);
|
|
116
|
+
const indexFile = await this.timed('index', () => this.storageProvider.getEntry(indexFileKey, [`${this.publishId}-${this.activeCollectionName}`, 'index']));
|
|
100
117
|
if (indexFile == null) {
|
|
101
118
|
console.error(`Index File not found at ${indexFileKey}.`);
|
|
102
119
|
console.error(`You may need to publish your application.`);
|
|
@@ -124,7 +141,9 @@ export class PublisherServer {
|
|
|
124
141
|
this.assetEntryMapCache = null;
|
|
125
142
|
return null;
|
|
126
143
|
}
|
|
127
|
-
|
|
144
|
+
// Read and parse in two steps, so that Server-Timing can report each one.
|
|
145
|
+
const indexText = await this.timed('index-body', () => indexFile.text());
|
|
146
|
+
this.assetEntryMapCache = await this.timed('index-parse', async () => JSON.parse(indexText));
|
|
128
147
|
return this.assetEntryMapCache;
|
|
129
148
|
}
|
|
130
149
|
async getMatchingAsset(assetKey, applyAuto = false) {
|
|
@@ -296,7 +315,7 @@ export class PublisherServer {
|
|
|
296
315
|
const baseHash = entry.key.slice(7);
|
|
297
316
|
const baseKey = `${this.publishId}_files_sha256_${baseHash}`;
|
|
298
317
|
const variantKey = variant != null ? `${baseKey}_${variant}` : baseKey;
|
|
299
|
-
const storageEntry = await this.storageProvider.getEntry(variantKey);
|
|
318
|
+
const storageEntry = await this.timed('asset', () => this.storageProvider.getEntry(variantKey));
|
|
300
319
|
if (storageEntry == null) {
|
|
301
320
|
return null;
|
|
302
321
|
}
|
|
@@ -380,6 +399,9 @@ export class PublisherServer {
|
|
|
380
399
|
if (asset.lastModifiedTime !== 0) {
|
|
381
400
|
headers.set('Last-Modified', (new Date(asset.lastModifiedTime * 1000)).toUTCString());
|
|
382
401
|
}
|
|
402
|
+
if (this.serverTiming != null) {
|
|
403
|
+
headers.append('Server-Timing', this.serverTiming.toHeaderValue());
|
|
404
|
+
}
|
|
383
405
|
const preconditionResponse = this.handlePreconditions(request, asset, headers);
|
|
384
406
|
if (preconditionResponse != null) {
|
|
385
407
|
return preconditionResponse;
|
|
@@ -391,6 +413,7 @@ export class PublisherServer {
|
|
|
391
413
|
});
|
|
392
414
|
}
|
|
393
415
|
async serveRequest(request) {
|
|
416
|
+
this.beginRequest(request);
|
|
394
417
|
// Only handle GET and HEAD
|
|
395
418
|
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
396
419
|
return null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-timing.d.ts","sourceRoot":"","sources":["../../../../src/server/util/server-timing.ts"],"names":[],"mappings":"AAaA,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAA2B;IAE1C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAItC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAS/E,aAAa,IAAI,MAAM;CAWxB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
// Collects durations for one request and formats them as a Server-Timing
|
|
6
|
+
// header value (https://www.w3.org/TR/server-timing/).
|
|
7
|
+
export class ServerTiming {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.entries = [];
|
|
10
|
+
}
|
|
11
|
+
add(name, dur, desc) {
|
|
12
|
+
this.entries.push({ name, dur, desc });
|
|
13
|
+
}
|
|
14
|
+
async measure(name, fn, desc) {
|
|
15
|
+
const start = performance.now();
|
|
16
|
+
try {
|
|
17
|
+
return await fn();
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
this.add(name, performance.now() - start, desc);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
toHeaderValue() {
|
|
24
|
+
return this.entries
|
|
25
|
+
.map(({ name, dur, desc }) => {
|
|
26
|
+
let value = `${name};dur=${dur.toFixed(1)}`;
|
|
27
|
+
if (desc != null) {
|
|
28
|
+
value += `;desc=${JSON.stringify(desc)}`;
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
})
|
|
32
|
+
.join(', ');
|
|
33
|
+
}
|
|
34
|
+
}
|
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.15",
|
|
5
5
|
"description": "Static Publisher for Fastly Compute JavaScript",
|
|
6
6
|
"main": "build/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"homepage": "https://github.com/fastly/compute-js-static-publish#readme",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@aws-sdk/client-s3": "3.888.0",
|
|
44
|
-
"@fastly/cli": "^16.0.0",
|
|
45
44
|
"command-line-args": "^5.2.1",
|
|
46
45
|
"glob-to-regexp": "^0.4.1",
|
|
47
46
|
"toml": "^3.0.0"
|