@@ -8,37 +8,6 @@ import {
88 * @typedef {import('./bindings').RuntimeEnvironmentName } RuntimeEnvironmentName
99 */
1010
11- /**
12- * Default configuration values to be used in test and dev if no explicit definition is found.
13- *
14- * @type Record<string, string>
15- */
16- export const DEFAULT_CONFIG_VALUES = {
17- SALT : 'secret' ,
18- DEBUG : 'true' ,
19- DATABASE_URL : 'http://localhost:3000' ,
20- DATABASE_TOKEN :
21- 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsImlhdCI6MTYwMzk2ODgzNCwiZXhwIjoyNTUwNjUzNjM0LCJyb2xlIjoic2VydmljZV9yb2xlIn0.necIJaiP7X2T2QjGeV-FhpkizcNTX8HjDDBAxpgQTEI' ,
22- CLUSTER_API_URL : 'http://localhost:9094' ,
23- CLUSTER_BASIC_AUTH_TOKEN : 'dGVzdDp0ZXN0' , // test:test
24- MAGIC_SECRET_KEY : 'test' ,
25- ENV : 'test' ,
26- SENTRY_DSN : 'https://test@test.ingest.sentry.io/0000000' ,
27- NFT_STORAGE_BRANCH : 'test' ,
28- NFT_STORAGE_VERSION : 'test' ,
29- NFT_STORAGE_COMMITHASH : 'test' ,
30- MAINTENANCE_MODE : 'rw' ,
31- METAPLEX_AUTH_TOKEN : 'metaplex-test-token' ,
32- MAILCHIMP_API_KEY : '' ,
33- LOGTAIL_TOKEN : '' ,
34- S3_ENDPOINT : 'http://localhost:9095' ,
35- S3_REGION : 'test' ,
36- S3_ACCESS_KEY_ID : 'test' ,
37- S3_SECRET_ACCESS_KEY : 'test' ,
38- S3_BUCKET_NAME : 'test' ,
39- PRIVATE_KEY : 'xmbtWjE9eYuAxae9G65lQSkw36HV6H+0LSFq2aKqVwY=' ,
40- }
41-
4211/**
4312 * If the CLUSTER_SERVICE variable is set, the service URL will be resolved from here.
4413 *
@@ -49,12 +18,6 @@ const CLUSTER_SERVICE_URLS = {
4918 IpfsCluster3 : 'https://nft3.storage.ipfscluster.io/api/' ,
5019}
5120
52- /**
53- * @param {RuntimeEnvironmentName } env
54- * @returns {boolean } true if the named runtime environment should fallback to values from DEFAULT_CONFIG_VALUES if no config var is present.
55- */
56- const allowDefaultConfigValues = ( env ) => env === 'test' || env === 'dev'
57-
5821/** @type ServiceConfiguration|undefined */
5922let _globalConfig
6023
@@ -90,14 +53,6 @@ export const overrideServiceConfigForTesting = (config) => {
9053 *
9154 * Exported for testing. See {@link getServiceConfig} for main public accessor.
9255 *
93- * Config values are resolved by looking for global variables with the names matching the keys of {@link DEFAULT_CONFIG_VALUES}.
94- *
95- * If no global value is found for a variable, an error will be thrown if the runtimeEnvironment (ENV variable)
96- * is set to a "production like" environment.
97- *
98- * If {@link allowDefaultConfigValues} returns true for the current environment, the value from {@link DEFAULT_CONFIG_VALUES} will be
99- * used if a variable is missing.
100- *
10156 * @returns {ServiceConfiguration }
10257 */
10358export function loadServiceConfig ( ) {
@@ -114,13 +69,14 @@ export function loadServiceConfig() {
11469 * @returns {ServiceConfiguration }
11570 */
11671export function serviceConfigFromVariables ( vars ) {
117- let clusterUrl = vars . CLUSTER_API_URL
118- if ( vars . CLUSTER_SERVICE ) {
119- const serviceUrl = CLUSTER_SERVICE_URLS [ vars . CLUSTER_SERVICE ]
120- if ( ! serviceUrl ) {
72+ let clusterUrl
73+ if ( ! vars . CLUSTER_SERVICE ) {
74+ clusterUrl = vars . CLUSTER_API_URL
75+ } else {
76+ clusterUrl = CLUSTER_SERVICE_URLS [ vars . CLUSTER_SERVICE ]
77+ if ( ! clusterUrl ) {
12178 throw new Error ( `unknown cluster service: ${ vars . CLUSTER_SERVICE } ` )
12279 }
123- clusterUrl = serviceUrl
12480 }
12581
12682 return {
@@ -135,9 +91,6 @@ export function serviceConfigFromVariables(vars) {
13591 CLUSTER_BASIC_AUTH_TOKEN : vars . CLUSTER_BASIC_AUTH_TOKEN ,
13692 MAGIC_SECRET_KEY : vars . MAGIC_SECRET_KEY ,
13793 SENTRY_DSN : vars . SENTRY_DSN ,
138- NFT_STORAGE_BRANCH : vars . NFT_STORAGE_BRANCH ,
139- NFT_STORAGE_VERSION : vars . NFT_STORAGE_VERSION ,
140- NFT_STORAGE_COMMITHASH : vars . NFT_STORAGE_COMMITHASH ,
14194 METAPLEX_AUTH_TOKEN : vars . METAPLEX_AUTH_TOKEN ,
14295 MAILCHIMP_API_KEY : vars . MAILCHIMP_API_KEY ,
14396 LOGTAIL_TOKEN : vars . LOGTAIL_TOKEN ,
@@ -147,6 +100,13 @@ export function serviceConfigFromVariables(vars) {
147100 S3_SECRET_ACCESS_KEY : vars . S3_SECRET_ACCESS_KEY ,
148101 S3_BUCKET_NAME : vars . S3_BUCKET_NAME ,
149102 PRIVATE_KEY : vars . PRIVATE_KEY ,
103+ // These are injected in esbuild
104+ // @ts -ignore
105+ BRANCH : NFT_STORAGE_BRANCH ,
106+ // @ts -ignore
107+ VERSION : NFT_STORAGE_VERSION ,
108+ // @ts -ignore
109+ COMMITHASH : NFT_STORAGE_COMMITHASH ,
150110 }
151111}
152112
@@ -166,29 +126,45 @@ export function loadConfigVariables() {
166126 /** @type Record<string, unknown> */
167127 const globals = globalThis
168128
169- const notFound = [ ]
170- for ( const name of Object . keys ( DEFAULT_CONFIG_VALUES ) ) {
129+ const required = [
130+ 'ENV' ,
131+ 'DEBUG' ,
132+ 'SALT' ,
133+ 'DATABASE_URL' ,
134+ 'DATABASE_TOKEN' ,
135+ 'MAGIC_SECRET_KEY' ,
136+ 'MAILCHIMP_API_KEY' ,
137+ 'METAPLEX_AUTH_TOKEN' ,
138+ 'LOGTAIL_TOKEN' ,
139+ 'PRIVATE_KEY' ,
140+ 'SENTRY_DSN' ,
141+ 'CLUSTER_BASIC_AUTH_TOKEN' ,
142+ 'MAINTENANCE_MODE' ,
143+ 'S3_REGION' ,
144+ 'S3_ACCESS_KEY_ID' ,
145+ 'S3_SECRET_ACCESS_KEY' ,
146+ 'S3_BUCKET_NAME' ,
147+ ]
148+
149+ for ( const name of required ) {
171150 const val = globals [ name ]
172151 if ( typeof val === 'string' ) {
173152 vars [ name ] = val
174153 } else {
175- notFound . push ( name )
176- }
177- }
178-
179- if ( notFound . length !== 0 ) {
180- const env = parseRuntimeEnv ( vars . ENV )
181- if ( ! allowDefaultConfigValues ( env ) ) {
182154 throw new Error (
183- ' Missing required config variables: ' + notFound . join ( ', ' )
155+ ` Missing required config variables: ${ name } . Check your .env, testing globals or cloudflare vars.`
184156 )
185157 }
186- console . warn (
187- 'Using default values for config variables: ' ,
188- notFound . join ( ', ' )
189- )
190- for ( const name of notFound ) {
191- vars [ name ] = DEFAULT_CONFIG_VALUES [ name ]
158+ }
159+
160+ const optional = [ 'CLUSTER_SERVICE' , 'CLUSTER_API_URL' , 'S3_ENDPOINT' ]
161+
162+ for ( const name of optional ) {
163+ const val = globals [ name ]
164+ if ( typeof val === 'string' ) {
165+ vars [ name ] = val
166+ } else {
167+ console . warn ( `Missing optional config variables: ${ name } ` )
192168 }
193169 }
194170
0 commit comments