@sjcrh/proteinpaint-server 2.199.0 → 2.201.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.
@@ -118,6 +118,16 @@ if (!serverconfig.binpath) {
118
118
  }
119
119
  }
120
120
 
121
+ if (!serverconfig.features) {
122
+ /*
123
+ default to having an empty object value for end-user-accessible features
124
+ necessary to ensure features{} object is set, as later when bootstraping a dataset, ds.serverconfigFeatures{} will be copied over
125
+ NOTE serverconfig.json settings takes highest priority!! these are instance-level setting, e.g. on your dev computer
126
+ and overwrites default values from ds.serverconfigFeatures{} to assist e.g. dev work
127
+ */
128
+ serverconfig.features = {}
129
+ }
130
+
121
131
  if (serverconfig.debugmode && !serverconfig.binpath.includes('sjcrh/')) {
122
132
  // only apply optional routeSetters in debugmode and when the binpath
123
133
  // indicates the server code is not installed as a node_module
@@ -176,6 +186,51 @@ if (serverconfig.debugmode) {
176
186
  const hg38test = serverconfig.genomes.find(g => g.name == 'hg38-test')
177
187
  // this internal function must be trusted to only modify test-related serverconfig entries
178
188
  if (hg38test?.datasets) mayUpdateTestDatasets(hg38test.datasets, serverconfig)
189
+
190
+ if (serverconfig.features.altGenomeByDslabel) {
191
+ /* features.altGenomeByDslabel = {dslabel: genomeName} makes the app middleware serve a dataset with an
192
+ alternate genome, e.g. {"GDC":"hg38-gdc"} to test against a dev-only genome file. When the named genome is
193
+ not declared in serverconfig.genomes[], every request to that dataset silently fails with "invalid genome",
194
+ which is very confusing since the genome supplied by the client (e.g. hg38) is in fact valid.
195
+ Fail at launch instead. */
196
+ const alt = serverconfig.features.altGenomeByDslabel
197
+ if (typeof alt != 'object' || Array.isArray(alt))
198
+ throw 'serverconfig.features.altGenomeByDslabel must be an object of {dslabel: genomeName}'
199
+ for (const dslabel in alt) {
200
+ const genomeName = alt[dslabel]
201
+ if (!serverconfig.genomes.find(g => g.name == genomeName))
202
+ throw `serverconfig.features.altGenomeByDslabel["${dslabel}"]="${genomeName}" is not a genome declared in serverconfig.genomes[]`
203
+ console.log(`dataset ${dslabel} now uses genome ${genomeName}`)
204
+ }
205
+ }
206
+ } else {
207
+ /****************************
208
+ these serverconfig.features are only meaningful in a dev/test environment: either they weaken a
209
+ protection that prod relies on, or the code path they enable is gated on debugmode/dev-only files and
210
+ so silently does nothing in prod. Enabling any of them in prod is a config mistake, so fail at launch
211
+ rather than let it go unnoticed. Only a truthy value is rejected, so e.g. "sse": false is still allowed.
212
+ NOTE the whole serverconfig.features{} object is returned to the client by the /genomes route,
213
+ so a stray dev-only entry is also visible to every embedder. */
214
+ const devOnlyFeatures = {
215
+ // serves a dataset with an alternate genome, for testing against a dev-only genome file
216
+ altGenomeByDslabel: 'only for testing a dataset against an alternate genome file in local dev',
217
+ // bypasses the allowedEmbedders/dsCredentials check in app.middlewares.js setHeaders()
218
+ loosenCORS: 'would allow any origin to embed this server, bypassing serverconfig.allowedEmbedders[]',
219
+ // client rewrites the session embedder host/origin, defeating the cross-origin check in app.parseurl.js
220
+ overrideEmbedderHostInMassSession: 'would let a mass session file be opened from a mismatched embedder',
221
+ // skips the launch-time samtools/bcftools/R library validation
222
+ skip_checkDependenciesAndVersions: 'prod must verify its dependencies at launch',
223
+ // writes request/response fixtures under publicDir, and is already gated on debugmode at runtime
224
+ cacheTestData: 'only writes test fixtures for the local test runner',
225
+ // the sse route file is under src/test/routes/ and is not deployed to prod
226
+ sse: 'the sse route is a dev-only test route',
227
+ // only read by the debugmode-only coverage test route
228
+ coverageKey: 'only used by the dev-only code coverage route'
229
+ }
230
+ for (const key in devOnlyFeatures) {
231
+ if (serverconfig.features[key])
232
+ throw `serverconfig.features.${key} is only allowed when serverconfig.debugmode is true: ${devOnlyFeatures[key]}`
233
+ }
179
234
  }
180
235
 
181
236
  if (serverconfig.allow_env_overrides) {
@@ -236,16 +291,6 @@ if (process.env.PP_MODE?.startsWith('container')) {
236
291
  })
237
292
  }
238
293
 
239
- if (!serverconfig.features) {
240
- /*
241
- default to having an empty object value for end-user-accessible features
242
- necessary to ensure features{} object is set, as later when bootstraping a dataset, ds.serverconfigFeatures{} will be copied over
243
- NOTE serverconfig.json settings takes highest priority!! these are instance-level setting, e.g. on your dev computer
244
- and overwrites default values from ds.serverconfigFeatures{} to assist e.g. dev work
245
- */
246
- serverconfig.features = {}
247
- }
248
-
249
294
  // when a mandatory setting is not defined in any ds, declare its default here
250
295
 
251
296
  if (process.argv.find(a => a == 'validate')) {