Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Dec 16, 2024
1 parent 81eb44c commit c09038b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 21 deletions.
13 changes: 10 additions & 3 deletions packages/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,18 @@ cli
.option('-c, --customer <email>', 'Billing account email')
.option('-na, --no-account', 'Skip account setup')
.option('-a, --account <email>', 'Managing account email')
.option('-ag, --authorize-gateway-services <json>', 'Authorize Gateways to serve the content uploaded to this space, e.g: \'[{"id":"did:key:z6Mki...","serviceEndpoint":"https://gateway.example.com"}]\'')
.option(
'-ag, --authorize-gateway-services <json>',
'Authorize Gateways to serve the content uploaded to this space, e.g: \'[{"id":"did:key:z6Mki...","serviceEndpoint":"https://gateway.example.com"}]\''
)
.option('-nga, --no-gateway-authorization', 'Skip Gateway Authorization')
.action((name, options) => {
let authorizeGatewayServices = []
if (options['authorize-gateway-services']) {
try {
authorizeGatewayServices = JSON.parse(options['authorize-gateway-services'])
authorizeGatewayServices = JSON.parse(
options['authorize-gateway-services']
)
} catch (err) {
console.error('Invalid JSON format for --authorize-gateway-services')
process.exit(1)
Expand All @@ -148,7 +153,9 @@ cli
const parsedOptions = {
...options,
// if defined it means we want to skip gateway authorization, so the client will not validate the gateway services
skipGatewayAuthorization: options['gateway-authorization'] === false || options['gateway-authorization'] === undefined,
skipGatewayAuthorization:
options['gateway-authorization'] === false ||
options['gateway-authorization'] === undefined,
// default to empty array if not set, so the client will validate the gateway services
authorizeGatewayServices: authorizeGatewayServices || [],
}
Expand Down
17 changes: 9 additions & 8 deletions packages/cli/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const provision = async (name = '', options = {}) => {
const { ok: bytes, error: fetchError } = await fetch(options.coupon)
.then((response) => response.arrayBuffer())
.then((buffer) => Result.ok(new Uint8Array(buffer)))
.catch((error) => Result.error(/** @type {Error} */(error)))
.catch((error) => Result.error(/** @type {Error} */ (error)))

if (fetchError) {
console.error(`Failed to fetch coupon from ${options.coupon}`)
Expand Down Expand Up @@ -247,7 +247,8 @@ export const provision = async (name = '', options = {}) => {

if (result.error) {
console.error(
`⚠️ Failed to set up billing account,\n ${Object(result.error).message ?? ''
`⚠️ Failed to set up billing account,\n ${
Object(result.error).message ?? ''
}`
)
process.exit(1)
Expand Down Expand Up @@ -286,7 +287,7 @@ const chooseSpace = (client, { name }) => {
* @param {W3Space.Model} space
* @param {CreateOptions} options
*/
export const setupEmailRecovery = async (space, options = {}) => { }
export const setupEmailRecovery = async (space, options = {}) => {}

/**
* @param {string} email
Expand Down Expand Up @@ -348,8 +349,8 @@ const chooseName = async (name, spaces) => {
name === ''
? 'What would you like to call this space?'
: space
? `Name "${space.name}" is already taken, please choose a different one`
: null
? `Name "${space.name}" is already taken, please choose a different one`
: null

if (message == null) {
return name
Expand Down Expand Up @@ -416,9 +417,9 @@ export const setupAccount = async (client) => {

return email
? await Account.loginWithClient(
/** @type {DIDMailto.EmailAddress} */(email),
client
)
/** @type {DIDMailto.EmailAddress} */ (email),
client
)
: null
}

Expand Down
40 changes: 35 additions & 5 deletions packages/cli/test/bin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ export const testSpace = {

'storacha space create home --no-caution': test(async (assert, context) => {
const create = storacha
.args(['space', 'create', 'home', '--no-caution', '--no-gateway-authorization'])
.args([
'space',
'create',
'home',
'--no-caution',
'--no-gateway-authorization',
])
.env(context.env.alice)
.fork()

Expand All @@ -160,7 +166,13 @@ export const testSpace = {
'storacha space create my-space --no-recovery': test(
async (assert, context) => {
const create = storacha
.args(['space', 'create', 'home', '--no-recovery', '--no-gateway-authorization'])
.args([
'space',
'create',
'home',
'--no-recovery',
'--no-gateway-authorization',
])
.env(context.env.alice)
.fork()

Expand All @@ -179,7 +191,13 @@ export const testSpace = {
await selectPlan(context)

const create = storacha
.args(['space', 'create', 'home', '--no-recovery', '--no-gateway-authorization'])
.args([
'space',
'create',
'home',
'--no-recovery',
'--no-gateway-authorization',
])
.env(context.env.alice)
.fork()

Expand All @@ -197,7 +215,13 @@ export const testSpace = {
await login(context, { email: 'alice@email.me' })

const create = storacha
.args(['space', 'create', 'my-space', '--no-recovery', '--no-gateway-authorization'])
.args([
'space',
'create',
'my-space',
'--no-recovery',
'--no-gateway-authorization',
])
.env(context.env.alice)
.fork()

Expand Down Expand Up @@ -313,7 +337,13 @@ export const testSpace = {

const { output, error } = await storacha
.env(context.env.alice)
.args(['space', 'create', 'home', '--no-recovery', '--no-gateway-authorization'])
.args([
'space',
'create',
'home',
'--no-recovery',
'--no-gateway-authorization',
])
.join()

assert.match(output, /billing account is set/i)
Expand Down
1 change: 1 addition & 0 deletions packages/w3up-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"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",
"dev": "tsc --build --watch",
"check": "tsc --build",
Expand Down
14 changes: 9 additions & 5 deletions packages/w3up-client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ export class Client extends Base {
* In addition, it authorizes the listed Gateway Services to serve content from the created space.
* It is done by delegating the `space/content/serve/*` capability to the Gateway Service.
* User can skip the Gateway authorization by setting the `skipGatewayAuthorization` option to `true`.
* If no gateways are specified or the `skipGatewayAuthorization` flag is not set, the client will automatically grant access
* to the Storacha Gateway by default (https://freewaying.dag.haus/).
*
* @typedef {import('./types.js').ConnectionView<import('./types.js').ContentServeService>} ConnectionView
*
Expand Down Expand Up @@ -311,10 +313,10 @@ export class Client extends Base {
UcantoClient.connect({
id: {
did: () =>
/** @type {`did:${string}:${string}`} */(
/* c8 ignore next - default prod gateway id is not used in tests */
process.env.DEFAULT_GATEWAY_ID ?? 'did:web:w3s.link'
),
/** @type {`did:${string}:${string}`} */ (
/* c8 ignore next - default prod gateway id is not used in tests */
process.env.DEFAULT_GATEWAY_ID ?? 'did:web:w3s.link'
),
},
codec: CAR.outbound,
channel: HTTP.open({
Expand Down Expand Up @@ -611,7 +613,9 @@ export const authorizeContentServe = async (
/* c8 ignore next 8 - can't mock this error */
if (verificationResult.out.error) {
throw new Error(
`failed to publish delegation for audience ${audience.did()}: ${verificationResult.out.error.message}`,
`failed to publish delegation for audience ${audience.did()}: ${
verificationResult.out.error.message
}`,
{
cause: verificationResult.out.error,
}
Expand Down

0 comments on commit c09038b

Please sign in to comment.