diff --git a/src/components/code.tsx b/src/components/code.tsx index f092019..4f6f7fb 100644 --- a/src/components/code.tsx +++ b/src/components/code.tsx @@ -4,6 +4,7 @@ import { Lang, Theme } from 'shiki' const w3upExample = ` import * as Client from '@web3-storage/w3up-client' import { filesFromPaths } from 'files-from-path' +import * as UcantoClient from '@ucanto/client' const client = await Client.create() @@ -11,12 +12,19 @@ const client = await Client.create() if (!Object.keys(client.accounts()).length) { // waits for you to click the link in your email to verify your identity const account = await client.login('you@example.org') - // create a space for your uploads - const space = await client.createSpace('lets-go') + // connect to the Gateway that will serve your content + const storachaGateway = UcantoClient.connect({ + id: id, + codec: CAR.outbound, + channel: url ? HTTP.open({ url: new URL('https://freeway.dag.haus') }) : server, + }) + // create a space for your uploads and authorize the gateway + const space = await client.createSpace('lets-go', { + account, // associate this space with your account & configure recovery + authorizeGatewayServices: [storachaGateway], + }) // save the space to the store, and set as "current" await space.save() - // associate this space with your account - await account.provision(space.did()) } // content-address your files diff --git a/src/pages/download-sc.md b/src/pages/download-sc.md index c235f3c..a6e3e70 100644 --- a/src/pages/download-sc.md +++ b/src/pages/download-sc.md @@ -1,9 +1,6 @@ # Download Source Code + Download the w3up client source code and start building today. Simply click the download button below to get the complete package. Questions or need help? Check out our documentation or reach out to support@storacha.network. - [Download here](https://github.com/storacha/w3up/archive/refs/heads/main.zip) - - - diff --git a/src/pages/how-to/create-space.mdx b/src/pages/how-to/create-space.mdx index 36691dc..a287b2b 100644 --- a/src/pages/how-to/create-space.mdx +++ b/src/pages/how-to/create-space.mdx @@ -31,8 +31,8 @@ The Space you create can be used to [upload](/how-to/upload/) data using the CLI ## Using the JS client 1. Install the client library from npm using your command line: `npm install @web3-storage/w3up-client`. -2. Call `client.createSpace('Documents')` and wait for the promise to resolve. +2. Execute `client.createSpace('Documents', { skipGatewayAuthorization: true })` and wait for the promise to resolve. - The space must be provisioned by an account before it can be used for uploads. See [our guide](/w3up-client/#create-and-provision-a-space) for details. + The space must be provisioned by an account before it can be used for uploads. Additionally, it needs to authorize a Gateway to serve the files you upload. See [our guide](/w3up-client/#create-and-provision-a-space) for more details. diff --git a/src/pages/w3up-client.md b/src/pages/w3up-client.md index 1595094..9c27ab0 100644 --- a/src/pages/w3up-client.md +++ b/src/pages/w3up-client.md @@ -51,25 +51,57 @@ If your account doesn't have a payment plan yet, you'll be prompted to select on await account.plan.wait(); ``` -Spaces can be created using the `createSpace` client method: +Spaces can be created using the `createSpace` client method. When creating a space, you must specify which Gateways will have permission to serve the content you upload. To do this, you first need to establish a connection with the Gateway. This connection allows client to publish the delegations required for the Gateway to serve your content: ```js -const space = await client.createSpace("my-awesome-space", { account }); -``` +import * as UcantoClient from '@ucanto/client' -Alternatively, you can use the w3cli command [`w3 space create`](https://github.com/storacha/w3cli#w3-space-create-name). +const storachaGateway = UcantoClient.connect({ + id: id, + codec: CAR.outbound, + channel: url ? HTTP.open({ url: new URL('https://freeway.dag.haus') }) : server, +}); +``` -The `name` parameter is optional. If provided, it will be stored in your client's local state store and can be used to provide a friendly name for user interfaces. +Once connected to the Gateway, you can create a space: -If an `account` is provided in the options, a delegated recovery account is automatically created and provisioned, allowing you to store data and delegate access to the recovery account. This means you can access your space from other devices, as long as you have access to your account. +```js +const space = await client.createSpace("my-awesome-space", { + account, + authorizeGatewayServices: [storachaGateway], +}); +``` -If this is your Agent's first space, it will automatically be set as the "current space." If you already have spaces and want to set the new one as current, you can do so manually: +If you want to ensure that no Gateway is authorized to serve the content of your space, you can use the `skipGatewayAuthorization` flag: ```js -await client.setCurrentSpace(space.did()); +const space = await client.createSpace("my-awesome-space", { + account, + skipGatewayAuthorization: true, +}); ``` -ℹ️ Note: If you do not create the space passing the account parameter you run the risk of losing access to your space! +Alternatively, you can use the `w3cli` command [`w3 space create`](https://github.com/storacha/w3cli#w3-space-create-name) for a streamlined approach. + +**Additional Notes** + +1. :warning: **Important** :warning: + If you do not provide the `account` parameter when creating a space, you risk losing access to your space in case of device loss or credential issues. + +2. **Account Parameter**\ + Supplying an `account` in the options automatically provisions a delegated recovery account. This enables you to store data securely and delegate access to the recovery account, allowing access to your space from other devices as long as you have your account credentials. + +3. **Name Parameter**\ + The `name` parameter is optional. If provided, it will be stored in your client’s local state and can serve as a user-friendly identifier for interfaces. + +4. **Current Space** + + - If this is your Agent's first space, it will be automatically set as the "current space." + - For additional spaces, you can manually set a new space as the current one using: + + ```js + await client.setCurrentSpace(space.did()); + ``` ## Upload files