@@ -5,25 +5,27 @@ import { DeploymentConfig } from "./types"
5
5
import * as TypesGen from "./typesGenerated"
6
6
7
7
// Adds 304 for the default axios validateStatus function
8
- // https://github.com/axios/axios#handling-errors
9
- // Check status here https://httpstatusdogs.com/
8
+ // https://github.com/axios/axios#handling-errors Check status here
9
+ // https://httpstatusdogs.com/
10
10
axios . defaults . validateStatus = ( status ) => {
11
11
return ( status >= 200 && status < 300 ) || status === 304
12
12
}
13
13
14
14
export const hardCodedCSRFCookie = ( ) : string => {
15
- // This is a hard coded CSRF token/cookie pair for local development.
16
- // In prod, the GoLang webserver generates a random cookie with a new token for
17
- // each document request. For local development, we don't use the Go webserver for static files,
18
- // so this is the 'hack' to make local development work with remote apis.
19
- // The CSRF cookie for this token is "JXm9hOUdZctWt0ZZGAy9xiS/gxMKYOThdxjjMnMUyn4="
15
+ // This is a hard coded CSRF token/cookie pair for local development. In prod,
16
+ // the GoLang webserver generates a random cookie with a new token for each
17
+ // document request. For local development, we don't use the Go webserver for
18
+ // static files, so this is the 'hack' to make local development work with
19
+ // remote apis. The CSRF cookie for this token is
20
+ // "JXm9hOUdZctWt0ZZGAy9xiS/gxMKYOThdxjjMnMUyn4="
20
21
const csrfToken =
21
22
"KNKvagCBEHZK7ihe2t7fj6VeJ0UyTDco1yVUJE8N06oNqxLu5Zx1vRxZbgfC0mJJgeGkVjgs08mgPbcWPBkZ1A=="
22
23
axios . defaults . headers . common [ "X-CSRF-TOKEN" ] = csrfToken
23
24
return csrfToken
24
25
}
25
26
26
- // withDefaultFeatures sets all unspecified features to not_entitled and disabled.
27
+ // withDefaultFeatures sets all unspecified features to not_entitled and
28
+ // disabled.
27
29
export const withDefaultFeatures = (
28
30
fs : Partial < TypesGen . Entitlements [ "features" ] > ,
29
31
) : TypesGen . Entitlements [ "features" ] => {
@@ -40,9 +42,8 @@ export const withDefaultFeatures = (
40
42
return fs as TypesGen . Entitlements [ "features" ]
41
43
}
42
44
43
- // Always attach CSRF token to all requests.
44
- // In puppeteer the document is undefined. In those cases, just
45
- // do nothing.
45
+ // Always attach CSRF token to all requests. In puppeteer the document is
46
+ // undefined. In those cases, just do nothing.
46
47
const token =
47
48
typeof document !== "undefined"
48
49
? document . head . querySelector ( 'meta[property="csrf-token"]' )
@@ -978,7 +979,8 @@ export class MissingBuildParameters extends Error {
978
979
* - Get the latest template to access the latest active version
979
980
* - Get the current build parameters
980
981
* - Get the template parameters
981
- * - Update the build parameters and check if there are missed parameters for the newest version
982
+ * - Update the build parameters and check if there are missed parameters for
983
+ * the newest version
982
984
* - If there are missing parameters raise an error
983
985
* - Create a build with the latest version and updated build parameters
984
986
*/
@@ -1017,12 +1019,22 @@ const getMissingParameters = (
1017
1019
templateParameters : TypesGen . TemplateVersionParameter [ ] ,
1018
1020
) => {
1019
1021
const missingParameters : TypesGen . TemplateVersionParameter [ ] = [ ]
1020
- const requiredParameters = templateParameters . filter (
1021
- // It is required
1022
- // and it can be changed
1023
- // and it is not from a legacy variable
1024
- ( p ) => p . required && p . mutable && p . legacy_variable_name === undefined ,
1025
- )
1022
+ const requiredParameters : TypesGen . TemplateVersionParameter [ ] = [ ]
1023
+
1024
+ templateParameters . forEach ( ( p ) => {
1025
+ // Legacy parameters should be required. So we can migrate them.
1026
+ const isLegacy = p . legacy_variable_name === undefined
1027
+ // It is mutable and required. Mutable values can be changed after so we
1028
+ // don't need to ask them if they are not required.
1029
+ const isMutableAndRequired = p . mutable && p . required
1030
+ // Is immutable, so we can check if it is its first time on the build
1031
+ const isImmutable = ! p . mutable
1032
+
1033
+ if ( isLegacy || isMutableAndRequired || isImmutable ) {
1034
+ requiredParameters . push ( p )
1035
+ return
1036
+ }
1037
+ } )
1026
1038
1027
1039
for ( const parameter of requiredParameters ) {
1028
1040
// Check if there is a new value
@@ -1049,7 +1061,8 @@ const getMissingParameters = (
1049
1061
/**
1050
1062
*
1051
1063
* @param agentId
1052
- * @returns An EventSource that emits agent metadata event objects (ServerSentEvent)
1064
+ * @returns An EventSource that emits agent metadata event objects
1065
+ * (ServerSentEvent)
1053
1066
*/
1054
1067
export const watchAgentMetadata = ( agentId : string ) : EventSource => {
1055
1068
return new EventSource (
0 commit comments