(argv: ArgumentsCamelCase<CommandArgs>)
| 56 | .epilog(buildEpilog({ command, apiDocs: 'listSchemaAppInvitations' })) |
| 57 | |
| 58 | const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => { |
| 59 | const command = await apiCommand(argv) |
| 60 | |
| 61 | type InvitationProviderFunction = () => Promise<InvitationWithAppDetails[]> |
| 62 | const listFn = (client: SmartThingsClient, appId?: string): InvitationProviderFunction => |
| 63 | async (): Promise<InvitationWithAppDetails[]> => { |
| 64 | // We have to be careful to not use the method to get a single app. For more |
| 65 | // details see `getSchemaAppEnsuringOrganization` in schema-utils. |
| 66 | const apps = appId |
| 67 | ? (await client.schema.list({ includeAllOrganizations: true })) |
| 68 | .filter(app => app.endpointAppId === appId) |
| 69 | : await client.schema.list() |
| 70 | return (await Promise.all(apps.map(async app => { |
| 71 | return app.endpointAppId |
| 72 | ? (await client.invitesSchema.list(app.endpointAppId)) |
| 73 | .map(invite => addAppDetails(invite, app)) |
| 74 | : [] |
| 75 | }))).flat() |
| 76 | } |
| 77 | |
| 78 | const config: OutputItemOrListConfig<InvitationWithAppDetails> = { |
| 79 | primaryKeyName: 'id', |
| 80 | sortKeyName: 'sort', |
| 81 | itemName: 'schema app invitation', |
| 82 | listTableFieldDefinitions: [{ prop: 'id', label: 'Invitation Id' }, 'schemaAppName', 'description'], |
| 83 | tableFieldDefinitions, |
| 84 | } |
| 85 | await outputItemOrList( |
| 86 | command, |
| 87 | config, |
| 88 | argv.idOrIndex, |
| 89 | listFn(command.client, argv.schemaApp), |
| 90 | id => getSingleInvite(command.client, argv.schemaApp, id)) |
| 91 | } |
| 92 | |
| 93 | const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler } |
| 94 | export default cmd |
nothing calls this directly
no test coverage detected