@openneuro/server 4.44.4 → 4.44.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openneuro/server",
3
- "version": "4.44.4",
3
+ "version": "4.44.6",
4
4
  "description": "Core service for the OpenNeuro platform.",
5
5
  "license": "MIT",
6
6
  "main": "src/server.js",
@@ -21,9 +21,9 @@
21
21
  "@elastic/elasticsearch": "8.13.1",
22
22
  "@graphql-tools/schema": "^10.0.0",
23
23
  "@keyv/redis": "^4.5.0",
24
- "@openneuro/search": "^4.44.4",
25
- "@sentry/node": "^8.25.0",
26
- "@sentry/profiling-node": "^8.25.0",
24
+ "@openneuro/search": "^4.44.6",
25
+ "@sentry/node": "^10.37.0",
26
+ "@sentry/profiling-node": "^10.37.0",
27
27
  "base64url": "^3.0.0",
28
28
  "cookie-parser": "^1.4.6",
29
29
  "cors": "^2.8.5",
@@ -89,5 +89,5 @@
89
89
  "publishConfig": {
90
90
  "access": "public"
91
91
  },
92
- "gitHead": "1f19e9260ba364a821864f48233e281507c0640a"
92
+ "gitHead": "1c266a5a49f11d604ea83725661c7896df40eca1"
93
93
  }
@@ -14,7 +14,7 @@ import * as subscriptions from "../handlers/subscriptions"
14
14
  import { generateDataladCookie } from "../libs/authentication/jwt"
15
15
  import { redis } from "../libs/redis"
16
16
  import CacheItem, { CacheType } from "../cache/item"
17
- import { updateDatasetRevision } from "./draft"
17
+ import { getDraftRevision, updateDatasetRevision } from "./draft"
18
18
  import { encodeFilePath, filesUrl, fileUrl, getFileName } from "./files"
19
19
  import { getAccessionNumber } from "../libs/dataset"
20
20
  import Dataset from "../models/dataset"
@@ -80,28 +80,6 @@ export const createDataset = async (
80
80
  }
81
81
  }
82
82
 
83
- interface WorkerDraftFields {
84
- // Commit id hash
85
- ref: string
86
- // Commit tree ref
87
- tree: string
88
- // Commit message
89
- message: string
90
- // Commit author time
91
- modified: string
92
- }
93
-
94
- /**
95
- * Return the latest commit
96
- * @param {string} id Dataset accession number
97
- */
98
- export const getDraftHead = async (id): Promise<WorkerDraftFields> => {
99
- const draftRes = await request
100
- .get(`${getDatasetWorker(id)}/datasets/${id}/draft`)
101
- .set("Accept", "application/json")
102
- return draftRes.body
103
- }
104
-
105
83
  /**
106
84
  * Fetch dataset document and related fields
107
85
  */
@@ -109,7 +87,7 @@ export const getDataset = async (id) => {
109
87
  const dataset = await Dataset.findOne({ id }).lean()
110
88
  return {
111
89
  ...dataset,
112
- revision: (await getDraftHead(id)).ref,
90
+ revision: getDraftRevision(id),
113
91
  }
114
92
  }
115
93
 
@@ -24,6 +24,7 @@ import { derivatives } from "./derivatives"
24
24
  import { promiseTimeout } from "../../utils/promiseTimeout"
25
25
  import { datasetEvents } from "./datasetEvents"
26
26
  import semver from "semver"
27
+ import { getDraftInfo } from "../../datalad/draft"
27
28
 
28
29
  export const dataset = async (obj, { id }, { user, userInfo }) => {
29
30
  await checkDatasetRead(id, user, userInfo)
@@ -280,7 +281,7 @@ const worker = (obj) => getDatasetWorker(obj.id)
280
281
  const Dataset = {
281
282
  uploader: (ds, _, context) => user(ds, { id: ds.uploader }, context),
282
283
  draft: async (obj) => {
283
- const draftHead = await datalad.getDraftHead(obj.id)
284
+ const draftHead = await getDraftInfo(obj.id)
284
285
  return {
285
286
  id: obj.id,
286
287
  revision: draftHead.ref,
@@ -14,11 +14,11 @@ import DeprecatedSnapshot from "../../models/deprecatedSnapshot"
14
14
  import { redis } from "../../libs/redis"
15
15
  import CacheItem, { CacheType } from "../../cache/item"
16
16
  import { normalizeDOI } from "../../libs/doi/normalize"
17
- import { getDraftHead } from "../../datalad/dataset"
18
17
  import { downloadFiles } from "../../datalad/snapshots"
19
18
  import { snapshotValidation } from "./validation"
20
19
  import { advancedDatasetSearchConnection } from "./dataset-search"
21
20
  import { contributors } from "../../datalad/contributors"
21
+ import { getDraftInfo } from "../../datalad/draft"
22
22
 
23
23
  export const snapshots = (obj) => {
24
24
  return datalad.getSnapshots(obj.id)
@@ -279,7 +279,7 @@ export const latestSnapshot = async (obj, _, context) => {
279
279
  // In the case where there are no real snapshots, return most recent commit as snapshot
280
280
  return await snapshot(
281
281
  obj,
282
- { datasetId: obj.id, tag: (await getDraftHead(obj.id)).ref },
282
+ { datasetId: obj.id, tag: (await getDraftInfo(obj.id)).ref },
283
283
  context,
284
284
  )
285
285
  }
@@ -2,6 +2,7 @@ import passport from "passport"
2
2
  import refresh from "passport-oauth2-refresh"
3
3
  import jwt from "jsonwebtoken"
4
4
  import * as Sentry from "@sentry/node"
5
+ import type { Request } from "express"
5
6
  import { decrypt } from "./crypto"
6
7
  import User from "../../models/user"
7
8
  import config from "../../config"
@@ -175,6 +176,19 @@ const refreshToken = async (jwt) => {
175
176
  // Shared options for Express response.cookie()
176
177
  const cookieOptions = { sameSite: "Lax" }
177
178
 
179
+ // Obtain client IP address from request, considering possible proxies
180
+ function getClientIp(req: Request): string | undefined {
181
+ const forwardedForHeader = req.headers["x-forwarded-for"]
182
+ if (forwardedForHeader) {
183
+ const ips = Array.isArray(forwardedForHeader)
184
+ ? forwardedForHeader
185
+ : forwardedForHeader.split(",")
186
+ const clientIp = ips[0].trim()
187
+ return clientIp
188
+ }
189
+ return req.socket.remoteAddress || undefined
190
+ }
191
+
178
192
  // attach user obj to request based on jwt
179
193
  // if user does not exist, continue
180
194
  export const authenticate = (req, res, next) => {
@@ -192,7 +206,7 @@ export const authenticate = (req, res, next) => {
192
206
  if (user) {
193
207
  Sentry.setUser({
194
208
  id: user.id,
195
- ip_address: req.headers["x-forwarded-for"] as string,
209
+ ip_address: getClientIp(req),
196
210
  })
197
211
  }
198
212
  Sentry.setContext("request_headers", {
package/src/sentry.ts CHANGED
@@ -4,7 +4,8 @@ import config from "./config"
4
4
  import { version } from "./lerna.json"
5
5
 
6
6
  Sentry.init({
7
- dsn: config.sentry.DSN,
7
+ dsn:
8
+ "https://baebfdeb279ddb0c39c876feefd464c8@o4507748938350592.ingest.us.sentry.io/4507750879461376",
8
9
  environment: config.sentry.ENVIRONMENT,
9
10
  integrations: [
10
11
  nodeProfilingIntegration(),