Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unified client #1306

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"react": "^18.2.0",
"typedoc": "^0.25.3",
"typedoc-plugin-markdown": "^3.17.0",
"typescript": "5.2.2"
"typescript": "^5.4.2"
},
"prettier": {
"trailingComma": "es5",
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"mocha": "^10.2.0",
"playwright-test": "^12.3.4",
"sinon": "^15.0.3",
"typescript": "5.2.2",
"typescript": "^5.4.2",
"watch": "^1.0.2"
},
"eslintConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/drivers/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ConfDriver {
this.path = this.#config.path
}

async open() {}
async connect() {}

async close() {}

Expand Down
4 changes: 2 additions & 2 deletions packages/access-client/src/drivers/indexeddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ export class IndexedDBDriver {
async #getOpenDB() {
if (!this.#db) {
if (!this.#autoOpen) throw new Error('Store is not open')
await this.open()
await this.connect()
}
// @ts-expect-error open sets this.#db
return this.#db
}

async open() {
async connect() {
const db = this.#db
if (db) return

Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/drivers/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class MemoryDriver {
this.#data = undefined
}

async open() {}
async connect() {}

async close() {}

Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/drivers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface Driver<T> {
/**
* Open driver
*/
open: () => Promise<void>
connect: () => Promise<void>
/**
* Clean up and close driver
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/access-client/src/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export const { Provider: ProviderDID, AccountDID } = Provider
* that delegation from the account authorizing agent is either stored in the
* agent proofs or provided explicitly.
*
* @template {Record<string, any>} [S=API.Service]
* @param {API.Agent<S>} agent
* @param {API.Agent<API.AccessService>} agent
* @param {object} input
* @param {API.AccountDID} input.account - Account provisioning the space.
* @param {API.SpaceDID} input.consumer - Space been provisioned.
Expand Down
4 changes: 3 additions & 1 deletion packages/access-client/test/helpers/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Signer } from '@ucanto/principal/ed25519'

/** did:key:z6Mkqa4oY9Z5Pf5tUcjLHLUsDjKwMC95HGXdE1j22jkbhz6r */
/** did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi */
export const alice = Signer.parse(
'MgCZT5vOnYZoVAeyjnzuJIVY9J4LNtJ+f8Js0cTPuKUpFne0BVEDJjEu6quFIU8yp91/TY/+MYK8GvlKoTDnqOCovCVM='
)

/** did:key:z6MkffDZCkCTWreg8868fG1FGFogcJj5X6PY93pPcWDn9bob */
export const bob = Signer.parse(
'MgCYbj5AJfVvdrjkjNCxB3iAUwx7RQHVQ7H1sKyHy46Iose0BEevXgL1V73PD9snOCIoONgb+yQ9sycYchQC8kygR4qY='
Expand All @@ -13,6 +14,7 @@ export const mallory = Signer.parse(
'MgCYtH0AvYxiQwBG6+ZXcwlXywq9tI50G2mCAUJbwrrahkO0B0elFYkl3Ulf3Q3A/EvcVY0utb4etiSE8e6pi4H0FEmU='
)

/** did:key:z6MkrZ1r5XBFZjBU34qyD8fueMbMRkKw17BZaq2ivKFjnz2z */
export const service = Signer.parse(
'MgCYKXoHVy7Vk4/QjcEGi+MCqjntUiasxXJ8uJKY0qh11e+0Bs8WsdqGK7xothgrDzzWD0ME7ynPjz2okXDh8537lId8='
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('IndexedDB store', () => {
})

const store = new StoreIndexedDB('test-access-db-' + Date.now())
await store.open()
await store.connect()
await store.save(data.export())

const exportData = await store.load()
Expand Down Expand Up @@ -40,13 +40,13 @@ describe('IndexedDB store', () => {
const store = new StoreIndexedDB('test-access-db-' + Date.now(), {
dbStoreName: `store-${Date.now()}`,
})
await store.open()
await store.connect()

const data0 = await AgentData.create()
await store.save(data0.export())

await store.close()
await store.open()
await store.connect()

const exportedData = await store.load()
assert(exportedData)
Expand All @@ -59,7 +59,7 @@ describe('IndexedDB store', () => {
const store = new StoreIndexedDB('test-access-db-' + Date.now(), {
autoOpen: false,
})
await store.open()
await store.connect()
await store.load()
await store.close()

Expand All @@ -71,7 +71,7 @@ describe('IndexedDB store', () => {

it('should round trip delegations', async () => {
const store = new StoreIndexedDB('test-access-db-' + Date.now())
await store.open()
await store.connect()

const data0 = await AgentData.create()
const signer = await EdSigner.generate()
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('IndexedDB store', () => {
const data = await AgentData.create({ principal })

const store = new StoreIndexedDB('test-access-db-' + Date.now())
await store.open()
await store.connect()
await store.save(data.export())

const exportData = await store.load()
Expand Down
2 changes: 1 addition & 1 deletion packages/capabilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"mocha": "^10.2.0",
"playwright-test": "^12.3.4",
"type-fest": "^3.3.0",
"typescript": "5.2.2",
"typescript": "^5.4.2",
"watch": "^1.0.2"
},
"eslintConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/capabilities/src/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const access = capability({
*/
export const authorize = capability({
can: 'access/authorize',
with: DID.match({ method: 'key' }),
with: DID.match({ method: 'key' }).or(DID.match({ method: 'mailto' })),
/**
* Authorization request describing set of desired capabilities
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/capabilities/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import * as UCAN from './ucan.js'
import * as Plan from './plan.js'
import * as Usage from './usage.js'

export * from './types.js'
export { capability, Schema } from '@ucanto/validator'

export {
Access,
Provider,
Expand Down
22 changes: 22 additions & 0 deletions packages/capabilities/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import * as AdminCaps from './admin.js'
import * as UCANCaps from './ucan.js'
import * as PlanCaps from './plan.js'
import * as UsageCaps from './usage.js'
import * as ConsoleCaps from './console.js'

export type ISO8601Date = string

Expand Down Expand Up @@ -80,6 +81,9 @@ export interface AccessAuthorizeSuccess {
}

export interface AccessAuthorizeFailure extends Ucanto.Failure {}
export interface AccessDenied extends Ucanto.Failure {
name: 'AccessDenied'
}

export type AccessClaim = InferInvokedCapability<typeof AccessCaps.claim>
export interface AccessClaimSuccess {
Expand Down Expand Up @@ -239,6 +243,24 @@ export type RateLimitListFailure = Ucanto.Failure
// Space
export type Space = InferInvokedCapability<typeof space>
export type SpaceInfo = InferInvokedCapability<typeof info>
export type SpaceInfoSuccess = {
did: SpaceDID
providers: ProviderDID[]
}
export type SpaceInfoFailure = Failure | SpaceUnknown

export interface SpaceUnknown extends Failure {
name: 'SpaceUnknown'
}

export type ConsoleLog = InferInvokedCapability<typeof ConsoleCaps.log>
export type ConsoleLogOk = {}
export type ConsoleError = InferInvokedCapability<typeof ConsoleCaps.error>
export type ConsoleErrorError = {
name: 'Error'
message: string
cause: unknown
}

// filecoin
export interface DealMetadata {
Expand Down
6 changes: 3 additions & 3 deletions packages/capabilities/test/helpers/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parseLink } from '@ucanto/core'
import { Absentee } from '@ucanto/principal'
import { Signer } from '@ucanto/principal/ed25519'

/** did:key:z6Mkqa4oY9Z5Pf5tUcjLHLUsDjKwMC95HGXdE1j22jkbhz6r */
/** did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi */
export const alice = Signer.parse(
'MgCZT5vOnYZoVAeyjnzuJIVY9J4LNtJ+f8Js0cTPuKUpFne0BVEDJjEu6quFIU8yp91/TY/+MYK8GvlKoTDnqOCovCVM='
)
Expand All @@ -28,10 +28,10 @@ export const mallory = Signer.parse(
export const malloryAccount = Absentee.from({
id: 'did:mailto:test.web3.storage:mallory',
})

/** did:key:z6MkrZ1r5XBFZjBU34qyD8fueMbMRkKw17BZaq2ivKFjnz2z */
export const service = Signer.parse(
'MgCYKXoHVy7Vk4/QjcEGi+MCqjntUiasxXJ8uJKY0qh11e+0Bs8WsdqGK7xothgrDzzWD0ME7ynPjz2okXDh8537lId8='
).withDID('did:web:test.web3.storage')
)

export const readmeCID = parseLink(
'bafybeihqfdg2ereoijjoyrqzr2x2wsasqm2udurforw7pa3tvbnxhojao4'
Expand Down
2 changes: 1 addition & 1 deletion packages/did-mailto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@types/mocha": "^10.0.1",
"@web3-storage/eslint-config-w3up": "workspace:^",
"mocha": "^10.2.0",
"typescript": "5.2.2"
"typescript": "^5.4.2"
},
"eslintConfig": {
"extends": [
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"multiformats": "^12.1.2",
"one-webcrypto": "git://github.com/web3-storage/one-webcrypto",
"p-wait-for": "^5.0.2",
"typescript": "5.2.2"
"typescript": "^5.4.2"
},
"eslintConfig": {
"extends": [
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"multiformats": "^12.1.2",
"npm-run-all": "^4.1.5",
"playwright-test": "^12.3.4",
"typescript": "5.2.2"
"typescript": "^5.4.2"
},
"eslintConfig": {
"extends": [
Expand Down
2 changes: 1 addition & 1 deletion packages/upload-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"is-subset": "^0.1.1",
"mocha": "^10.2.0",
"one-webcrypto": "git://github.com/web3-storage/one-webcrypto",
"typescript": "5.2.2"
"typescript": "^5.4.2"
},
"eslintConfig": {
"extends": [
Expand Down
13 changes: 4 additions & 9 deletions packages/upload-api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type ValidationEmailSend = {
url: string
}

export type { SpaceInfoSuccess, SpaceInfoFailure, SpaceUnknown }
export type SpaceDID = DIDKey
export type ServiceDID = DID<'web'>
export type ServiceSigner = Signer<ServiceDID>
Expand Down Expand Up @@ -117,6 +118,9 @@ import {
ProviderAddSuccess,
ProviderAddFailure,
SpaceInfo,
SpaceInfoSuccess,
SpaceInfoFailure,
SpaceUnknown,
ProviderDID,
StoreGetFailure,
UploadGetFailure,
Expand Down Expand Up @@ -446,12 +450,6 @@ export interface UploadTable {
) => Promise<ListResponse<UploadListItem>>
}

export type SpaceInfoSuccess = {
did: SpaceDID
providers: ProviderDID[]
}
export type SpaceInfoFailure = Failure | SpaceUnknown

export interface UnknownProvider extends Failure {
name: 'UnknownProvider'
}
Expand Down Expand Up @@ -513,9 +511,6 @@ export interface TestSpaceRegistry {
export interface LinkJSON<T extends UnknownLink = UnknownLink> {
'/': ToString<T>
}
export interface SpaceUnknown extends Failure {
name: 'SpaceUnknown'
}

export type Input<C extends CapabilityParser<Match<ParsedCapability>>> =
ProviderInput<InferInvokedCapability<C> & ParsedCapability>
Expand Down
2 changes: 1 addition & 1 deletion packages/upload-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"mocha": "^10.2.0",
"npm-run-all": "^4.1.5",
"playwright-test": "^12.3.4",
"typescript": "5.2.2"
"typescript": "^5.4.2"
},
"eslintConfig": {
"extends": [
Expand Down
23 changes: 18 additions & 5 deletions packages/w3up-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@
},
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"node": "./src/index.node.js",
"import": "./src/index.js"
"types": "./dist/src/lib.ts",
"import": "./src/lib.js"
},
"./store": {
"types": "./dist/src/store.d.ts",
"node": "./src/store.node.js",
"import": "./src/store.js"
},
"./agent/signer": {
"types": "./dist/src/agent/signer.d.ts",
"browser": "./src/agent/signer.browser.js",
"import": "./src/agent/signer.js"
},
"./account": {
"types": "./dist/src/account.d.ts",
Expand Down Expand Up @@ -100,11 +109,15 @@
"@ucanto/interface": "^9.0.0",
"@ucanto/principal": "^9.0.0",
"@ucanto/transport": "^9.0.0",
"datalogia": "^0.4.0",
"conf": "11.0.2",
"@web3-storage/access": "workspace:^",
"@web3-storage/capabilities": "workspace:^",
"@web3-storage/did-mailto": "workspace:^",
"@web3-storage/filecoin-client": "workspace:^",
"@web3-storage/upload-client": "workspace:^"
"@web3-storage/upload-client": "workspace:^",
"@scure/bip39": "^1.2.1",
"uint8arrays": "^4.0.9"
},
"devDependencies": {
"@ipld/car": "^5.1.1",
Expand All @@ -123,7 +136,7 @@
"npm-run-all": "^4.1.5",
"playwright-test": "^12.3.4",
"typedoc": "^0.25.3",
"typescript": "^5.2.2"
"typescript": "^5.4.2"
},
"eslintConfig": {
"extends": [
Expand Down
Loading
Loading