@@ -3,7 +3,7 @@ import * as CAR from '@ucanto/transport/car'
33import { SpaceDID } from '@web3-storage/capabilities/utils'
44import { Verifier , Signer } from '@ucanto/principal/ed25519'
55import { HTTP } from '@ucanto/transport'
6- import { Usage } from './withUcantoClient. capabilities.js '
6+ import { Space } from '@web3-storage/ capabilities'
77
88/**
99 * @import { Middleware } from '@web3-storage/gateway-lib'
@@ -46,7 +46,7 @@ async function create (env) {
4646 * @returns {Promise<void> }
4747 */
4848 record : async ( space , resource , bytes , servedAt ) =>
49- recordEgress ( space , resource , bytes , servedAt , principal , service , connection ) ,
49+ egressRecord ( space , resource , bytes , servedAt , principal , service , connection ) ,
5050
5151 /**
5252 * TODO: implement this function
@@ -91,17 +91,19 @@ async function connect (serverUrl, principal) {
9191 * @param {any } connection - The connection to execute the command
9292 * @returns {Promise<void> }
9393 */
94- async function recordEgress ( space , resource , bytes , servedAt , principal , service , connection ) {
95- const res = await Usage . record . invoke ( {
96- issuer : principal ,
97- audience : service ,
98- with : SpaceDID . from ( space ) ,
99- nb : {
100- resource,
101- bytes,
102- servedAt : Math . floor ( servedAt . getTime ( ) / 1000 )
103- }
104- } ) . execute ( connection )
94+ async function egressRecord ( space , resource , bytes , servedAt , principal , service , connection ) {
95+ const res = await Space . egressRecord
96+ . invoke ( {
97+ issuer : principal ,
98+ audience : service ,
99+ with : SpaceDID . from ( space ) ,
100+ nb : {
101+ resource,
102+ bytes,
103+ servedAt : Math . floor ( servedAt . getTime ( ) / 1000 )
104+ }
105+ } )
106+ . execute ( connection )
105107
106108 if ( res . out . error ) {
107109 console . error ( 'Failed to record egress' , res . out . error )
0 commit comments