Skip to content

Commit a15f8a6

Browse files
committed
fix tests
1 parent bd768f9 commit a15f8a6

13 files changed

+165
-86
lines changed

package-lock.json

Lines changed: 108 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"standard": "^17.1.0",
7171
"tree-kill": "^1.2.2",
7272
"typescript": "^5.6.3",
73-
"wrangler": "^3.85.0"
73+
"wrangler": "^3.86.1"
7474
},
7575
"standard": {
7676
"ignore": [

scripts/delegate-serve.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,24 @@ cli
3838
proofs = client.proofs([
3939
{
4040
can: Space.contentServe.can,
41-
with: spaceDID,
41+
with: spaceDID
4242
}
4343
])
4444
}
4545

4646
/** @type {import('@ucanto/client').Principal<`did:${string}:${string}`>} */
4747
const gatewayIdentity = {
48-
did: () => gatewayDID,
48+
did: () => gatewayDID
4949
}
5050

5151
// @ts-expect-error - The client still needs to be updated to support the capability type
5252
const delegation = await client.createDelegation(gatewayIdentity, [Space.contentServe.can], {
5353
expiration: Infinity,
54-
proofs,
54+
proofs
5555
})
5656

5757
await client.capability.access.delegate({
58-
delegations: [delegation],
58+
delegations: [delegation]
5959
})
6060

6161
const carResult = await delegation.archive()

src/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { NoopSpanProcessor } from '@opentelemetry/sdk-trace-base'
4646

4747
const handler = {
4848
/** @type {Handler<Context, Environment>} */
49-
fetch(request, env, ctx) {
49+
fetch (request, env, ctx) {
5050
console.log(request.method, request.url)
5151
const middleware = composeMiddleware(
5252
// Prepare the Context
@@ -60,11 +60,15 @@ const handler = {
6060
withAuthToken,
6161
withLocator,
6262
withGatewayIdentity,
63+
// TODO: replace this with a handler to fetch the real delegations
6364
withDelegationStubs,
6465

6566
// Rate-limit requests
6667
withRateLimit,
6768

69+
// Fetch CAR data - Double-check why this can't be placed after the authorized space middleware
70+
withCarBlockHandler,
71+
6872
// Authorize requests
6973
withAuthorizedSpace,
7074

@@ -73,7 +77,6 @@ const handler = {
7377
withEgressTracker,
7478

7579
// Fetch data
76-
withCarBlockHandler,
7780
withContentClaimsDagula,
7881
withFormatRawHandler,
7982
withFormatCarHandler,
@@ -91,7 +94,7 @@ const handler = {
9194
* @param {Environment} env
9295
* @param {*} _trigger
9396
*/
94-
function config(env, _trigger) {
97+
function config (env, _trigger) {
9598
if (env.HONEYCOMB_API_KEY) {
9699
return {
97100
exporter: {
@@ -103,7 +106,7 @@ function config(env, _trigger) {
103106
}
104107
return {
105108
spanProcessors: new NoopSpanProcessor(),
106-
service: { name: 'freeway' },
109+
service: { name: 'freeway' }
107110
}
108111
}
109112
export default process.env.FF_TELEMETRY_ENABLED === 'true'
@@ -113,7 +116,7 @@ export default process.env.FF_TELEMETRY_ENABLED === 'true'
113116
/**
114117
* @type {Middleware<BlockContext & UnixfsContext & IpfsUrlContext, BlockContext & UnixfsContext & IpfsUrlContext, Environment>}
115118
*/
116-
export function withFormatRawHandler(handler) {
119+
export function withFormatRawHandler (handler) {
117120
return async (request, env, ctx) => {
118121
const { headers } = request
119122
const { searchParams } = ctx
@@ -131,7 +134,7 @@ export function withFormatRawHandler(handler) {
131134
/**
132135
* @type {Middleware<DagContext & IpfsUrlContext, DagContext & IpfsUrlContext, Environment>}
133136
*/
134-
export function withFormatCarHandler(handler) {
137+
export function withFormatCarHandler (handler) {
135138
return async (request, env, ctx) => {
136139
const { headers } = request
137140
const { searchParams } = ctx

src/middleware/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export { withLocator } from './withLocator.js'
88
export { withEgressTracker } from './withEgressTracker.js'
99
export { withEgressClient } from './withEgressClient.js'
1010
export { withDelegationStubs } from './withDelegationStubs.js'
11-
export { withGatewayIdentity } from './withGatewayIdentity.js'
11+
export { withGatewayIdentity } from './withGatewayIdentity.js'

src/middleware/withAuthorizedSpace.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Verifier } from '@ucanto/principal'
22
import { ok, access, Unauthorized } from '@ucanto/validator'
33
import { HttpError } from '@web3-storage/gateway-lib/util'
44
import * as serve from '../capabilities/serve.js'
5-
import { Schema } from '@ucanto/client'
65

76
/**
87
* @import * as Ucanto from '@ucanto/interface'
@@ -103,7 +102,7 @@ const authorize = async (space, ctx) => {
103102
})
104103

105104
if (relevantDelegationsResult.error) return relevantDelegationsResult
106-
105+
107106
// Create an invocation of the serve capability.
108107
const invocation = await serve.transportHttp
109108
.invoke({
@@ -113,7 +112,7 @@ const authorize = async (space, ctx) => {
113112
nb: {
114113
token: ctx.authToken
115114
},
116-
proofs: relevantDelegationsResult.ok,
115+
proofs: relevantDelegationsResult.ok
117116
})
118117
.delegate()
119118

@@ -122,7 +121,7 @@ const authorize = async (space, ctx) => {
122121
capability: serve.transportHttp,
123122
authority: ctx.gatewayIdentity,
124123
principal: Verifier,
125-
validateAuthorization: () => ok({}),
124+
validateAuthorization: () => ok({})
126125
})
127126
if (accessResult.error) {
128127
return accessResult

0 commit comments

Comments
 (0)