Skip to content

Commit

Permalink
feat: add pre-built browser bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Jan 15, 2025
1 parent 1390106 commit e5af74b
Show file tree
Hide file tree
Showing 5 changed files with 290 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .attw.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"ignoreRules": ["cjs-resolves-to-esm"]
"ignoreRules": ["cjs-resolves-to-esm"],
"excludeEntrypoints": ["browser.min.js"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ docs
.env
.next
out
*.min.js

# debug
npm-debug.log*
Expand Down
16 changes: 15 additions & 1 deletion packages/w3up-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

This library is the user-facing "porcelain" client for interacting with w3up services from JavaScript. It wraps the lower-level [`@storacha/access`][access-client-github] and [`@storacha/upload-client`][upload-client-github] client packages, which target individual w3up services. We recommend using `@storacha/client` instead of using those "plumbing" packages directly, but you may find them useful if you need more context on w3up's architecture and internals.

**`w3up-client` requires Node 18 or higher**.
**`w3up-client` requires modern browser or Node 18+**.

> ⚠️❗ __Public Data__ 🌎: All data uploaded to w3up is available to anyone who requests it using the correct CID. Do not store any private or sensitive information in an unencrypted form using w3up.
Expand Down Expand Up @@ -117,6 +117,20 @@ const client = await create({ principal })

Once initialized, you can access the client's `Agent` with the [`agent` getter][docs-Client#agent].

##### Pre-built bundle
You can also import a pre-built bundle, which adds the exports from the client to a _global_ variable `w3up`:
```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@web3-storage/w3up-client/browser.min.js"></script>
<script>
async function main () {
const client = await w3up.create()
console.log(client.did())
}
main()
</script>
```

#### Creating and registering Spaces

A [`Space`][docs-Space] acts as a namespace for your uploads, and what your Agent will need a delegation from to store data with w3up. The first thing to do is login your Agent with your email address. Calling `login` will cause an email to be sent to the given address. Once a user clicks the confirmation link in the email, the `login` method will resolve. Make sure to check for errors, as `login` will fail if the email is not confirmed within the expiration timeout. Authorization needs to happen only once per agent.
Expand Down
14 changes: 11 additions & 3 deletions packages/w3up-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"types": "./dist/src/account.d.ts",
"import": "./dist/src/account.js"
},
"./browser.min.js": {
"default": "./browser.min.js"
},
"./delegation": {
"types": "./dist/src/delegation.d.ts",
"import": "./dist/src/delegation.js"
Expand Down Expand Up @@ -114,13 +117,16 @@
"access": "public"
},
"files": [
"dist"
"dist",
"*.min.js"
],
"scripts": {
"attw": "attw --pack .",
"lint": "tsc --build && eslint '**/*.{js,ts}' && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"lint:fix": "tsc --build && eslint '**/*.{js,ts}' --fix && prettier --write '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"build": "tsc --build",
"build": "npm run build:tsc && npm run build:bundle:browser",
"build:tsc": "tsc --build",
"build:bundle:browser": "esbuild src/index.js --bundle --minify --target=chrome130 --format=iife --global-name=w3up --outfile=browser.min.js",
"dev": "tsc --build --watch",
"check": "tsc --build",
"prepare": "npm run build",
Expand Down Expand Up @@ -166,6 +172,7 @@
"@web3-storage/w3up-client": "^16.5.1",
"assert": "^2.0.0",
"c8": "^7.13.0",
"esbuild": "^0.24.0",
"hundreds": "^0.0.9",
"mocha": "^10.8.2",
"multiformats": "^12.1.2",
Expand All @@ -192,7 +199,8 @@
"docs",
"docs-generated",
"coverage",
"src/types.js"
"src/types.js",
"*.min.js"
]
},
"directories": {
Expand Down
Loading

0 comments on commit e5af74b

Please sign in to comment.