Skip to content

Commit 889a198

Browse files
committed
fix lint
1 parent 518cbd9 commit 889a198

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@opentelemetry/sdk-trace-base": "^1.27.0",
4343
"@storacha/capabilities": "^1.10.0",
4444
"@storacha/indexing-service-client": "^2.6.6",
45-
"@types/node": "^24.9.1",
45+
"@types/node": "^24.10.1",
4646
"@ucanto/client": "^9.0.2",
4747
"@ucanto/core": "^10.4.5",
4848
"@ucanto/interface": "^11.0.1",
@@ -64,6 +64,7 @@
6464
"@storacha/upload-client": "^1.3.6",
6565
"@types/chai": "^5.0.0",
6666
"@types/mocha": "^10.0.9",
67+
"@types/node": "^24.10.1",
6768
"@types/node-fetch": "^2.6.11",
6869
"@types/sinon": "^17.0.3",
6970
"@web3-storage/content-claims": "^5.2.4",

src/middleware/withAuthorizedSpace.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { SpaceDID } from '@storacha/capabilities/utils'
77
/**
88
* Extracts a SpaceDID string from various space object formats.
99
* Handles string DIDs, objects with .did() method, and Uint8Arrays.
10-
*
10+
*
1111
* @param {any} space - The space object to extract DID from
1212
* @returns {import('@storacha/capabilities/types').SpaceDID | undefined}
1313
*/
14-
function extractSpaceDID(space) {
14+
function extractSpaceDID (space) {
1515
if (!space) return undefined
1616

1717
try {
@@ -83,7 +83,6 @@ export function withAuthorizedSpace (handler) {
8383
throw new Error(`failed to locate: ${dataCid}`, { cause: locRes.error })
8484
}
8585

86-
8786
// Legacy behavior: Site results which have no Space attached are from
8887
// before we started authorizing serving content explicitly. For these, we
8988
// always serve the content, but only if the request has no authorization
@@ -104,7 +103,7 @@ export function withAuthorizedSpace (handler) {
104103
const spaces = sitesWithSpace
105104
.map((site) => extractSpaceDID(site.space))
106105
.filter((space) => space !== undefined)
107-
106+
108107
try {
109108
// First space to successfully authorize is the one we'll use.
110109
const { space: selectedSpace, delegationProofs } = await Promise.any(
@@ -126,11 +125,11 @@ export function withAuthorizedSpace (handler) {
126125
// If all Spaces failed to authorize, return 404 (security through obscurity)
127126
if (error instanceof AggregateError) {
128127
// Check if all errors are authorization failures (not storage errors)
129-
const isAuthFailure = error.errors.every((e) =>
130-
e instanceof Unauthorized ||
128+
const isAuthFailure = error.errors.every((e) =>
129+
e instanceof Unauthorized ||
131130
(e.message && e.message.includes('not authorized to serve'))
132131
)
133-
132+
134133
if (isAuthFailure) {
135134
if (env.DEBUG === 'true') {
136135
console.log(
@@ -167,9 +166,9 @@ const authorize = async (space, ctx) => {
167166
if (relevantDelegationsResult.error) {
168167
return relevantDelegationsResult
169168
}
170-
169+
171170
const delegationProofs = relevantDelegationsResult.ok
172-
171+
173172
// If no delegations found, the server is not authorized to serve this content
174173
if (!delegationProofs || delegationProofs.length === 0) {
175174
return fail('The gateway is not authorized to serve this content.')
@@ -195,7 +194,7 @@ const authorize = async (space, ctx) => {
195194
principal: Verifier,
196195
validateAuthorization: () => ok({})
197196
})
198-
197+
199198
if (accessResult.error) {
200199
return accessResult
201200
}

src/middleware/withEgressTracker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ export function withEgressTracker (handler) {
8080
return
8181
}
8282
const serializedInvocation = archiveResult.ok
83-
83+
8484
// Non-blocking call to queue the invocation
8585
ctx.waitUntil(
8686
env.EGRESS_QUEUE.send({
8787
messageId: delegation.cid,
88-
invocation: serializedInvocation,
88+
invocation: serializedInvocation,
8989
timestamp: Date.now()
9090
})
9191
)

test/unit/middleware/withEgressTracker.spec.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const createContext = () => {
5555
const egressPromise = new Promise(resolve => {
5656
resolveEgress = resolve
5757
})
58-
58+
5959
return {
6060
space: SpaceDID.from(
6161
'did:key:z6MkknBAHEGCWvBzAi4amdH5FXEXrdKoWF1UJuvc8Psm2Mda'
@@ -66,10 +66,11 @@ const createContext = () => {
6666
gatewaySigner,
6767
gatewayIdentity,
6868
delegationProofs: [],
69+
// @ts-ignore - Fake waitUntil to capture promisses and wait for them before making test asserts
6970
waitUntil: (promise) => {
7071
// Track the promise synchronously
71-
const tracked = promise.catch(error => {
72-
// Ignore errors in waitUntil
72+
const tracked = promise.catch((error) => {
73+
console.error('Error in waitUntil:', error)
7374
})
7475
waitUntilPromises.push(tracked)
7576
// @ts-expect-error - Resolve the egress promise when all tracked promises complete
@@ -79,7 +80,7 @@ const createContext = () => {
7980
// Wait for egress tracking to complete
8081
waitForEgressTracking: () => egressPromise,
8182
path: '',
82-
searchParams: new URLSearchParams(),
83+
searchParams: new URLSearchParams()
8384
}
8485
}
8586

@@ -152,7 +153,6 @@ describe('withEgressTracker', async () => {
152153
it('should record egress for a large file', async () => {
153154
const ctx = createContext()
154155
const largeContent = new Uint8Array(100 * 1024 * 1024) // 100 MB
155-
const totalBytes = largeContent.byteLength
156156
const mockResponse = new Response(
157157
new ReadableStream({
158158
start (controller) {
@@ -184,7 +184,6 @@ describe('withEgressTracker', async () => {
184184
const ctx = createContext()
185185
const chunk1 = new TextEncoder().encode('Hello, ')
186186
const chunk2 = new TextEncoder().encode('world!')
187-
const totalBytes = Buffer.byteLength(chunk1) + Buffer.byteLength(chunk2)
188187

189188
const mockResponse = new Response(
190189
new ReadableStream({
@@ -227,7 +226,6 @@ describe('withEgressTracker', async () => {
227226
const carBytes = await bucket.get(key)
228227
expect(carBytes).to.be.not.undefined
229228
expect(carBytes).to.be.instanceOf(Uint8Array)
230-
const expectedTotalBytes = carBytes.byteLength
231229

232230
// Mock a response with the CAR file content
233231
const mockResponse = new Response(
@@ -278,7 +276,6 @@ describe('withEgressTracker', async () => {
278276
it('should correctly track egress for delayed responses', async () => {
279277
const ctx = createContext()
280278
const content = new TextEncoder().encode('Delayed response content')
281-
const totalBytes = Buffer.byteLength(content)
282279

283280
const mockResponse = new Response(
284281
new ReadableStream({
@@ -364,8 +361,6 @@ describe('withEgressTracker', async () => {
364361
const ctx = createContext()
365362
const content1 = new TextEncoder().encode('Hello, world!')
366363
const content2 = new TextEncoder().encode('Goodbye, world!')
367-
const totalBytes1 = Buffer.byteLength(content1)
368-
const totalBytes2 = Buffer.byteLength(content2)
369364

370365
const mockResponse1 = new Response(
371366
new ReadableStream({
@@ -420,7 +415,7 @@ describe('withEgressTracker', async () => {
420415
const queuedData1 = queueSendMock.args[0][0]
421416
expect(queuedData1).to.have.property('invocation')
422417
expect(queuedData1.invocation).to.be.instanceOf(Uint8Array)
423-
418+
424419
const queuedData2 = queueSendMock.args[1][0]
425420
expect(queuedData2).to.have.property('invocation')
426421
expect(queuedData2.invocation).to.be.instanceOf(Uint8Array)
@@ -538,12 +533,12 @@ describe('withEgressTracker', async () => {
538533
const response = await handler(request, {
539534
...env,
540535
EGRESS_QUEUE: {
541-
send: sinon.stub().throws("queue error"),
542-
sendBatch: sinon.stub().throws("queue error")
536+
send: sinon.stub().throws('queue error'),
537+
sendBatch: sinon.stub().throws('queue error')
543538
}
544539
}, ctx)
545540
const responseBody = await response.text()
546-
// Wait a bit to ensure flush callback has run and error was caught
541+
// @ts-ignore Wait a bit to ensure flush callback has run and error was caught
547542
await new Promise(resolve => setImmediate(resolve))
548543

549544
expect(response.status).to.equal(200)

0 commit comments

Comments
 (0)