Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Nov 13, 2024
1 parent bd768f9 commit a15f8a6
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 86 deletions.
138 changes: 108 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"standard": "^17.1.0",
"tree-kill": "^1.2.2",
"typescript": "^5.6.3",
"wrangler": "^3.85.0"
"wrangler": "^3.86.1"
},
"standard": {
"ignore": [
Expand Down
8 changes: 4 additions & 4 deletions scripts/delegate-serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ cli
proofs = client.proofs([
{
can: Space.contentServe.can,
with: spaceDID,
with: spaceDID
}
])
}

/** @type {import('@ucanto/client').Principal<`did:${string}:${string}`>} */
const gatewayIdentity = {
did: () => gatewayDID,
did: () => gatewayDID
}

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

await client.capability.access.delegate({
delegations: [delegation],
delegations: [delegation]
})

const carResult = await delegation.archive()
Expand Down
15 changes: 9 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { NoopSpanProcessor } from '@opentelemetry/sdk-trace-base'

const handler = {
/** @type {Handler<Context, Environment>} */
fetch(request, env, ctx) {
fetch (request, env, ctx) {
console.log(request.method, request.url)
const middleware = composeMiddleware(
// Prepare the Context
Expand All @@ -60,11 +60,15 @@ const handler = {
withAuthToken,
withLocator,
withGatewayIdentity,
// TODO: replace this with a handler to fetch the real delegations
withDelegationStubs,

// Rate-limit requests
withRateLimit,

// Fetch CAR data - Double-check why this can't be placed after the authorized space middleware
withCarBlockHandler,

// Authorize requests
withAuthorizedSpace,

Expand All @@ -73,7 +77,6 @@ const handler = {
withEgressTracker,

// Fetch data
withCarBlockHandler,
withContentClaimsDagula,
withFormatRawHandler,
withFormatCarHandler,
Expand All @@ -91,7 +94,7 @@ const handler = {
* @param {Environment} env
* @param {*} _trigger
*/
function config(env, _trigger) {
function config (env, _trigger) {
if (env.HONEYCOMB_API_KEY) {
return {
exporter: {
Expand All @@ -103,7 +106,7 @@ function config(env, _trigger) {
}
return {
spanProcessors: new NoopSpanProcessor(),
service: { name: 'freeway' },
service: { name: 'freeway' }
}
}
export default process.env.FF_TELEMETRY_ENABLED === 'true'
Expand All @@ -113,7 +116,7 @@ export default process.env.FF_TELEMETRY_ENABLED === 'true'
/**
* @type {Middleware<BlockContext & UnixfsContext & IpfsUrlContext, BlockContext & UnixfsContext & IpfsUrlContext, Environment>}
*/
export function withFormatRawHandler(handler) {
export function withFormatRawHandler (handler) {
return async (request, env, ctx) => {
const { headers } = request
const { searchParams } = ctx
Expand All @@ -131,7 +134,7 @@ export function withFormatRawHandler(handler) {
/**
* @type {Middleware<DagContext & IpfsUrlContext, DagContext & IpfsUrlContext, Environment>}
*/
export function withFormatCarHandler(handler) {
export function withFormatCarHandler (handler) {
return async (request, env, ctx) => {
const { headers } = request
const { searchParams } = ctx
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export { withLocator } from './withLocator.js'
export { withEgressTracker } from './withEgressTracker.js'
export { withEgressClient } from './withEgressClient.js'
export { withDelegationStubs } from './withDelegationStubs.js'
export { withGatewayIdentity } from './withGatewayIdentity.js'
export { withGatewayIdentity } from './withGatewayIdentity.js'
7 changes: 3 additions & 4 deletions src/middleware/withAuthorizedSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Verifier } from '@ucanto/principal'
import { ok, access, Unauthorized } from '@ucanto/validator'
import { HttpError } from '@web3-storage/gateway-lib/util'
import * as serve from '../capabilities/serve.js'
import { Schema } from '@ucanto/client'

/**
* @import * as Ucanto from '@ucanto/interface'
Expand Down Expand Up @@ -103,7 +102,7 @@ const authorize = async (space, ctx) => {
})

if (relevantDelegationsResult.error) return relevantDelegationsResult

// Create an invocation of the serve capability.
const invocation = await serve.transportHttp
.invoke({
Expand All @@ -113,7 +112,7 @@ const authorize = async (space, ctx) => {
nb: {
token: ctx.authToken
},
proofs: relevantDelegationsResult.ok,
proofs: relevantDelegationsResult.ok
})
.delegate()

Expand All @@ -122,7 +121,7 @@ const authorize = async (space, ctx) => {
capability: serve.transportHttp,
authority: ctx.gatewayIdentity,
principal: Verifier,
validateAuthorization: () => ok({}),
validateAuthorization: () => ok({})
})
if (accessResult.error) {
return accessResult
Expand Down
Loading

0 comments on commit a15f8a6

Please sign in to comment.