Skip to content

Commit

Permalink
Revert "feat: move validation flow to a Durable Object to make it ⏩ f…
Browse files Browse the repository at this point in the history
…ast ⏩ fast ⏩ fast ⏩ (#449)"

This reverts commit 02d7552.
  • Loading branch information
travis authored Mar 15, 2023
1 parent 8d98025 commit 84a7fb5
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 278 deletions.
2 changes: 1 addition & 1 deletion packages/access-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"toucan-js": "^2.7.0"
},
"devDependencies": {
"@cloudflare/workers-types": "^3.19.0",
"@cloudflare/workers-types": "^3.18.0",
"@databases/split-sql-query": "^1.0.3",
"@databases/sql": "^3.2.0",
"@sentry/cli": "2.7.0",
Expand Down
8 changes: 0 additions & 8 deletions packages/access-api/src/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ import { ProvisionsStorage } from './types/provisions.js'

export {}

export type {
DurableObjectNamespace,
DurableObjectState,
Response as WorkerResponse,
} from '@cloudflare/workers-types'

// CF Analytics Engine types not available yet
export interface AnalyticsEngine {
writeDataPoint: (event: AnalyticsEngineEvent) => void
Expand Down Expand Up @@ -59,7 +53,6 @@ export interface Env {
SPACES: KVNamespace
VALIDATIONS: KVNamespace
W3ACCESS_METRICS: AnalyticsEngine
SPACE_VERIFIERS: DurableObjectNamespace
// eslint-disable-next-line @typescript-eslint/naming-convention
__D1_BETA__: D1Database
}
Expand All @@ -78,7 +71,6 @@ export interface RouteContext {
validations: Validations
}
uploadApi: ConnectionView
spaceVerifiers: DurableObjectNamespace
}

export type Handler = _Handler<RouteContext>
Expand Down
131 changes: 0 additions & 131 deletions packages/access-api/src/durable-objects/space-verifier.js

This file was deleted.

4 changes: 0 additions & 4 deletions packages/access-api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { postRaw } from './routes/raw.js'
import { postRoot } from './routes/root.js'
import { preValidateEmail, validateEmail } from './routes/validate-email.js'
import { validateWS } from './routes/validate-ws.js'
import { validateWSDID } from './routes/validate-ws-did.js'
import { version } from './routes/version.js'
import { getContext } from './utils/context.js'

Expand All @@ -18,7 +17,6 @@ r.add('get', '/version', version)
r.add('get', '/validate-email', preValidateEmail)
r.add('post', '/validate-email', validateEmail)
r.add('get', '/validate-ws', validateWS)
r.add('get', '/validate-ws/:did', validateWSDID)
r.add('post', '/', postRoot)
r.add('post', '/raw', postRaw)

Expand All @@ -41,6 +39,4 @@ const worker = {
},
}

export { SpaceVerifier } from './durable-objects/space-verifier.js'

export default worker
17 changes: 1 addition & 16 deletions packages/access-api/src/models/validations.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { stringToDelegation } from '@web3-storage/access/encoding'
import { sendDelegationToSpaceVerifier } from '../durable-objects/space-verifier.js'

/**
* Validations
Expand All @@ -8,11 +7,9 @@ export class Validations {
/**
*
* @param {KVNamespace} kv
* @param {import('../bindings').DurableObjectNamespace | undefined} spaceVerifiers
*/
constructor(kv, spaceVerifiers) {
constructor(kv) {
this.kv = kv
this.spaceVerifiers = spaceVerifiers
}

/**
Expand All @@ -25,22 +22,10 @@ export class Validations {
stringToDelegation(ucan)
)

// TODO: remove this KV stuff once we have the durable objects stuff in production
await this.kv.put(delegation.audience.did(), ucan, {
expiration: delegation.expiration,
})

const cap =
/** @type import('@ucanto/interface').InferInvokedCapability<typeof import('@web3-storage/capabilities/voucher').redeem> */ (
delegation.capabilities[0]
)
if (this.spaceVerifiers && cap.nb?.space) {
await sendDelegationToSpaceVerifier(
this.spaceVerifiers,
cap.nb.space,
ucan
)
}
return delegation
}

Expand Down
17 changes: 0 additions & 17 deletions packages/access-api/src/routes/validate-ws-did.js

This file was deleted.

10 changes: 5 additions & 5 deletions packages/access-api/src/service/voucher-claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ export function voucherClaimProvider(ctx) {
.delegate()

const encoded = delegationToString(inv)
// For testing
if (ctx.config.ENV === 'test') {
return encoded
}

const url = `${ctx.url.protocol}//${ctx.url.host}/validate-email?ucan=${encoded}`

await ctx.email.sendValidation({
to: capability.nb.identity.replace('mailto:', ''),
url,
})

// For testing
if (ctx.config.ENV === 'test') {
return encoded
}
})
}
3 changes: 1 addition & 2 deletions packages/access-api/src/utils/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function getContext(request, env, ctx) {
})
),
spaces: new Spaces(config.DB),
validations: new Validations(config.VALIDATIONS, env.SPACE_VERIFIERS),
validations: new Validations(config.VALIDATIONS),
accounts: new Accounts(config.DB),
provisions: new DbProvisions(signer.did(), createD1Database(config.DB)),
},
Expand All @@ -87,6 +87,5 @@ export function getContext(request, env, ctx) {
url: new URL(config.UPLOAD_API_URL),
fetch: globalThis.fetch.bind(globalThis),
}),
spaceVerifiers: env.SPACE_VERIFIERS,
}
}
2 changes: 1 addition & 1 deletion packages/access-api/test/helpers/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dotenv.config({
})

/**
* @typedef {Omit<import('../../src/bindings').Env, 'SPACES'|'VALIDATIONS'|'__D1_BETA__'|'SPACE_VERIFIERS'>} AccessApiBindings - bindings object expected by access-api workers
* @typedef {Omit<import('../../src/bindings').Env, 'SPACES'|'VALIDATIONS'|'__D1_BETA__'>} AccessApiBindings - bindings object expected by access-api workers
*/

/**
Expand Down
Loading

0 comments on commit 84a7fb5

Please sign in to comment.