MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / handler

Function handler

src/commands/invites/schema.ts:58–91  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

56 .epilog(buildEpilog({ command, apiDocs: 'listSchemaAppInvitations' }))
57
58const 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
93const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
94export default cmd

Callers

nothing calls this directly

Calls 4

apiCommandFunction · 0.85
outputItemOrListFunction · 0.85
listFnFunction · 0.85
getSingleInviteFunction · 0.85

Tested by

no test coverage detected