diff --git a/packages/w3up-client/src/client.js b/packages/w3up-client/src/client.js index 096dcdbce..e0e096fa8 100644 --- a/packages/w3up-client/src/client.js +++ b/packages/w3up-client/src/client.js @@ -30,6 +30,9 @@ import { FilecoinClient } from './capability/filecoin.js' import { CouponAPI } from './coupon.js' export * as Access from './capability/access.js' import * as Result from './result.js' +import * as UcantoClient from '@ucanto/client' +import { HTTP } from '@ucanto/transport' +import * as CAR from '@ucanto/transport/car' export { AccessClient, @@ -304,16 +307,23 @@ export class Client extends Base { // Authorize the listed Gateway Services to serve content from the created space if (options.skipGatewayAuthorization !== true) { - if ( - !options.authorizeGatewayServices || - options.authorizeGatewayServices.length === 0 - ) { - throw new Error( - 'failed to authorize Gateway Services: missing option' - ) + let authorizeGatewayServices = options.authorizeGatewayServices + if (!authorizeGatewayServices || authorizeGatewayServices.length === 0) { + // If no Gateway Services are provided, authorize the Storacha Gateway Service + authorizeGatewayServices = [ + UcantoClient.connect({ + id: { + did: () => 'did:web:w3s.link', + }, + codec: CAR.outbound, + channel: HTTP.open({ + url: new URL(' https://freeway.dag.haus'), + }), + }), + ] } - for (const serviceConnection of options.authorizeGatewayServices) { + for (const serviceConnection of authorizeGatewayServices) { await authorizeContentServe(this, space, serviceConnection) } } diff --git a/packages/w3up-client/test/client.test.js b/packages/w3up-client/test/client.test.js index b64463bf4..c9e1d5350 100644 --- a/packages/w3up-client/test/client.test.js +++ b/packages/w3up-client/test/client.test.js @@ -656,7 +656,7 @@ export const testClient = { assert.fail(error, 'should not throw when creating the space') } }, - 'should throw when the content serve authorization fails due to missing service configuration': + 'should authorize the Storacha Gateway Service when no Gateway Services are provided': async (assert, { mail, grantAccess, connection }) => { // Step 1: Create a client for Alice and login const aliceClient = new Client( @@ -679,23 +679,14 @@ export const testClient = { await grantAccess(message) const aliceAccount = await aliceLogin - try { - const spaceA = await aliceClient.createSpace( - 'authorize-gateway-space', - { - account: aliceAccount, - authorizeGatewayServices: [], // No services to authorize - } - ) - assert.fail(spaceA, 'should not create the space') - } catch (error) { - assert.match( - // @ts-expect-error - error.message, - /missing option/, - 'should throw when creating the space' - ) - } + const spaceA = await aliceClient.createSpace( + 'authorize-gateway-space', + { + account: aliceAccount, + authorizeGatewayServices: [], // If no Gateway Services are provided, authorize the Storacha Gateway Service + } + ) + assert.ok(spaceA, 'should create the space') }, 'should throw when content serve service can not process the invocation': async (assert, { mail, grantAccess, connection }) => {