Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions packages/edge/src/commands/edge/channels/invites/accept.ts

This file was deleted.

95 changes: 0 additions & 95 deletions packages/edge/src/commands/edge/channels/invites/create.ts

This file was deleted.

34 changes: 0 additions & 34 deletions packages/edge/src/commands/edge/channels/invites/delete.ts

This file was deleted.

36 changes: 36 additions & 0 deletions src/commands/edge/channels/invites/accept.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs'

import { apiCommand, apiCommandBuilder, type APICommandFlags } from '../../../../lib/command/api-command.js'
import { edgeCommand } from '../../../../lib/command/edge-command.js'


export type CommandArgs =
& APICommandFlags
& {
id: string
}

const command = 'edge:channels:invites:accept <id>'

const describe = 'accept a channel invitation'

const builder = (yargs: Argv): Argv<CommandArgs> =>
apiCommandBuilder(yargs)
.positional('id', { describe: 'invite id', type: 'string', demandOption: true })
.example([
[
'$0 edge:channels:invites:accept e09f544d-4eb1-458f-899f-ff93d1ba9396',
'accept the specified invite',
],
])

const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
const command = edgeCommand(await apiCommand(argv))

const id = argv.id
await command.edgeClient.invites.accept(id)
console.log(`Invitation ${id} accepted.`)
}

const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
export default cmd
117 changes: 117 additions & 0 deletions src/commands/edge/channels/invites/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import inquirer from 'inquirer'
import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs'

import { type TableFieldDefinition } from '../../../../lib/table-generator.js'
import { apiCommand, apiCommandBuilder, type APICommandFlags } from '../../../../lib/command/api-command.js'
import { edgeCommand } from '../../../../lib/command/edge-command.js'
import {
inputAndOutputItem,
inputAndOutputItemBuilder,
type InputAndOutputItemFlags,
} from '../../../../lib/command/input-and-output-item.js'
import { userInputProcessor } from '../../../../lib/command/input-processor.js'
import { chooseChannel } from '../../../../lib/command/util/edge/channels-choose.js'
import { type Invitation, type InvitationCreate } from '../../../../lib/edge/endpoints/invites.js'


export type CommandArgs =
& APICommandFlags
& InputAndOutputItemFlags
& {
channel?: string
}

const command = 'edge:channels:invites:create'

const describe = 'create an invitation'

const builder = (yargs: Argv): Argv<CommandArgs> =>
inputAndOutputItemBuilder(apiCommandBuilder(yargs))
.option('channel', {
alias: 'C',
describe: 'channel id',
type: 'string',
conflicts: ['input'],
})
.example([
['$0 edge:channels:invites:create', 'create an invite from prompted input'],
[
'$0 edge:channels:invites:create --channel 19f12a0c-df0d-44fa-8cba-0d06fb206e42',
'create an invite from prompted input for the specified channel',
],
])

const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
const command = edgeCommand(await apiCommand(argv))

const getInputFromUser = async (): Promise<InvitationCreate> => {
const channelId = await chooseChannel(command, 'Choose a channel:', argv.channel,
{ useConfigDefault: true })

const name = (await inquirer.prompt({
type: 'input',
name: 'name',
message: 'Invitation name:',
validate: input => input ? true : 'name is required',
})).name as string

const description = (await inquirer.prompt({
type: 'input',
name: 'description',
message: 'Invitation description:',
validate: input => input ? true : 'description is required',
})).description as string

const owner = (await inquirer.prompt({
type: 'input',
name: 'owner',
message: 'Invitation owner:',
validate: input => input ? true : 'owner is required',
})).owner as string

const termsUrl = (await inquirer.prompt({
type: 'input',
name: 'termsUrl',
message: 'Invitation termsUrl:',
validate: input => input ? true : 'termsUrl is required',
})).termsUrl as string

const defaultInvitationProfileId = '61a79569-e8fd-4a4d-9b9c-a4a55ccdd15e'
const profileId = (command.profile.defaultInvitationProfileId as string)
?? defaultInvitationProfileId
return {
resource: {
root: {
service: 'developer',
},
components: [{
id: channelId,
kind: 'channel',
}],
},
profileId,
metadata: {
name,
description,
owner,
termsUrl,
},
}
}

const create = async (_: void, input: InvitationCreate): Promise<Invitation> => {
const { invitationId } = await command.edgeClient.invites.create(input)
const invitation = await command.edgeClient.invites.get(invitationId)
return invitation
}

const tableFieldDefinitions: TableFieldDefinition<Invitation>[] = [
'id',
{ path: 'metadata.name' },
'profileId', 'expiration', 'acceptUrl']

await inputAndOutputItem(command, { tableFieldDefinitions }, create, userInputProcessor(getInputFromUser))
}

const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
export default cmd
69 changes: 69 additions & 0 deletions src/commands/edge/channels/invites/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs'

import { apiCommand, apiCommandBuilder, type APICommandFlags } from '../../../../lib/command/api-command.js'
import { edgeCommand } from '../../../../lib/command/edge-command.js'
import { chooseChannel } from '../../../../lib/command/util/edge/channels-choose.js'
import { chooseInviteFn } from '../../../../lib/command/util/edge-invites-choose.js'


export type CommandArgs =
& APICommandFlags
& {
channel?: string
id?: string
}

const command = 'edge:channels:invites:delete [id]'

const describe = 'delete a channel invitation'

const builder = (yargs: Argv): Argv<CommandArgs> =>
apiCommandBuilder(yargs)
.option('channel', {
alias: 'C',
describe: 'channel id',
type: 'string',
conflicts: ['input'],
})
.positional('id', { describe: 'invite id', type: 'string' })
.example([
['$0 edge:channels:invites:delete', 'prompt for an invitation and delete it'],
[
'$0 edge:channels:invites:delete --channel 4af44f62-dbfd-45ec-831d-c3c2a6d57b97',
'prompt for an invitation to the specified channel and delete it',
],
[
'$0 edge:channels:invites:delete 929dc382-1b7b-43b0-a97b-577d2daecf0e',
'delete the specified invite',
],
])

const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
const command = edgeCommand(await apiCommand(argv))

const chooseInvite = async (): Promise<string> => {
if (argv.id) {
return argv.id
}

const channelId = await chooseChannel(
command,
'Which channel is the invite you want to delete for?',
argv.channel,
{ useConfigDefault: true },
)

return chooseInviteFn(command, { channelId })(
command,
argv.id,
{ promptMessage: 'Choose an invitation to delete.' },
)
}

const id = await chooseInvite()
await command.edgeClient.invites.delete(id)
console.log(`Invitation ${id} deleted.`)
}

const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
export default cmd
Loading