Skip to content

Commit

Permalink
update createSpace docs
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Forbeck <[email protected]>
  • Loading branch information
fforbeck committed Dec 11, 2024
1 parent 240cd91 commit 99535a2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
16 changes: 12 additions & 4 deletions src/components/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ 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()
// first time setup!
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('[email protected]')
// 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
Expand Down
5 changes: 1 addition & 4 deletions src/pages/download-sc.md
Original file line number Diff line number Diff line change
@@ -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 [email protected].


[Download here](https://github.com/storacha/w3up/archive/refs/heads/main.zip)



4 changes: 2 additions & 2 deletions src/pages/how-to/create-space.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<Callout>
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.
</Callout>
50 changes: 41 additions & 9 deletions src/pages/w3up-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 99535a2

Please sign in to comment.