From e75b1223b108dc90fd320c8f70a77551887f8067 Mon Sep 17 00:00:00 2001 From: Ross Stenersen Date: Fri, 27 Oct 2023 10:55:26 -0500 Subject: [PATCH] fix: ux tweaks to ST Schema invites --- .changeset/eighty-knives-sin.md | 8 ++ package-lock.json | 28 +++---- packages/cli/README.md | 40 --------- packages/cli/package.json | 2 +- .../lib/commands/invites-util.test.ts | 81 ++++++++++++++++--- packages/cli/src/commands/invites/schema.ts | 34 +++++--- .../invites/schema/check-acceptance.ts | 45 ----------- .../cli/src/commands/invites/schema/create.ts | 13 +-- .../cli/src/lib/commands/invites-utils.ts | 37 ++++++--- packages/edge/package.json | 2 +- packages/lib/package.json | 2 +- packages/testlib/package.json | 2 +- 12 files changed, 151 insertions(+), 143 deletions(-) create mode 100644 .changeset/eighty-knives-sin.md delete mode 100644 packages/cli/src/commands/invites/schema/check-acceptance.ts diff --git a/.changeset/eighty-knives-sin.md b/.changeset/eighty-knives-sin.md new file mode 100644 index 00000000..be9da96f --- /dev/null +++ b/.changeset/eighty-knives-sin.md @@ -0,0 +1,8 @@ +--- +"@smartthings/cli": patch +"@smartthings/plugin-cli-edge": patch +"@smartthings/cli-lib": patch +"@smartthings/cli-testlib": patch +--- + +minor ux tweaks to new ST Schema Invites diff --git a/package-lock.json b/package-lock.json index dc534445..1ea6c65b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4800,9 +4800,9 @@ "link": true }, "node_modules/@smartthings/core-sdk": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@smartthings/core-sdk/-/core-sdk-8.1.0.tgz", - "integrity": "sha512-EikiiWqBijAUpGRk5qJ5KuVHDAY0ps30dZaz9KhLj2b/6mtXOFgutySUG4fznqoMMJ25B1U2K33k7v8HEwnztA==", + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/@smartthings/core-sdk/-/core-sdk-8.1.1.tgz", + "integrity": "sha512-SyTg33ZpvvS4qkStoWmbLPK8+sxNE0mT/BMOiwqfuAUKlDU0MQAccE/JOY8BNDJtJtMjx2gc+3WQ7FsZS0ZT0g==", "dependencies": { "async-mutex": "^0.4.0", "axios": "^0.27.2", @@ -19842,7 +19842,7 @@ "@oclif/plugin-not-found": "^2.3.1", "@oclif/plugin-plugins": "^2.1.0", "@smartthings/cli-lib": "^2.2.2", - "@smartthings/core-sdk": "^8.1.0", + "@smartthings/core-sdk": "^8.1.1", "@smartthings/plugin-cli-edge": "^3.3.1", "inquirer": "^8.2.4", "js-yaml": "^4.1.0", @@ -19897,7 +19897,7 @@ "@log4js-node/log4js-api": "^1.0.2", "@oclif/core": "^1.16.3", "@smartthings/cli-lib": "^2.2.2", - "@smartthings/core-sdk": "^8.1.0", + "@smartthings/core-sdk": "^8.1.1", "axios": "^0.27.2", "inquirer": "^8.2.4", "js-yaml": "^4.1.0", @@ -19943,7 +19943,7 @@ "dependencies": { "@log4js-node/log4js-api": "^1.0.2", "@oclif/core": "^1.16.3", - "@smartthings/core-sdk": "^8.1.0", + "@smartthings/core-sdk": "^8.1.1", "@types/eventsource": "^1.1.9", "axios": "^0.27.2", "chalk": "^4.1.2", @@ -20009,7 +20009,7 @@ "license": "Apache-2.0", "dependencies": { "@smartthings/cli-lib": "^2.2.2", - "@smartthings/core-sdk": "^8.1.0" + "@smartthings/core-sdk": "^8.1.1" }, "devDependencies": { "@types/jest": "^28.1.5", @@ -23971,7 +23971,7 @@ "@oclif/plugin-plugins": "^2.1.0", "@smartthings/cli-lib": "^2.2.2", "@smartthings/cli-testlib": "^2.0.4", - "@smartthings/core-sdk": "^8.1.0", + "@smartthings/core-sdk": "^8.1.1", "@smartthings/plugin-cli-edge": "^3.3.1", "@types/inquirer": "^8.2.1", "@types/jest": "^28.1.5", @@ -24012,7 +24012,7 @@ "requires": { "@log4js-node/log4js-api": "^1.0.2", "@oclif/core": "^1.16.3", - "@smartthings/core-sdk": "^8.1.0", + "@smartthings/core-sdk": "^8.1.1", "@types/eventsource": "^1.1.9", "@types/express": "^4.17.13", "@types/inquirer": "^8.2.1", @@ -24066,7 +24066,7 @@ "version": "file:packages/testlib", "requires": { "@smartthings/cli-lib": "^2.2.2", - "@smartthings/core-sdk": "^8.1.0", + "@smartthings/core-sdk": "^8.1.1", "@types/jest": "^28.1.5", "@types/js-yaml": "^4.0.5", "@types/node": "^18.15.11", @@ -24086,9 +24086,9 @@ } }, "@smartthings/core-sdk": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@smartthings/core-sdk/-/core-sdk-8.1.0.tgz", - "integrity": "sha512-EikiiWqBijAUpGRk5qJ5KuVHDAY0ps30dZaz9KhLj2b/6mtXOFgutySUG4fznqoMMJ25B1U2K33k7v8HEwnztA==", + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/@smartthings/core-sdk/-/core-sdk-8.1.1.tgz", + "integrity": "sha512-SyTg33ZpvvS4qkStoWmbLPK8+sxNE0mT/BMOiwqfuAUKlDU0MQAccE/JOY8BNDJtJtMjx2gc+3WQ7FsZS0ZT0g==", "requires": { "async-mutex": "^0.4.0", "axios": "^0.27.2", @@ -24116,7 +24116,7 @@ "@oclif/core": "^1.16.3", "@smartthings/cli-lib": "^2.2.2", "@smartthings/cli-testlib": "^2.0.4", - "@smartthings/core-sdk": "^8.1.0", + "@smartthings/core-sdk": "^8.1.1", "@types/cli-table": "^0.3.0", "@types/eventsource": "^1.1.8", "@types/inquirer": "^8.2.1", diff --git a/packages/cli/README.md b/packages/cli/README.md index c38ce182..4cd2bcbc 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -207,7 +207,6 @@ that map to the API spec. * [`smartthings installedschema [ID]`](#smartthings-installedschema-id) * [`smartthings installedschema:delete [ID]`](#smartthings-installedschemadelete-id) * [`smartthings invites:schema [IDORINDEX]`](#smartthings-invitesschema-idorindex) -* [`smartthings invites:schema:check-acceptance [ID]`](#smartthings-invitesschemacheck-acceptance-id) * [`smartthings invites:schema:create`](#smartthings-invitesschemacreate) * [`smartthings invites:schema:delete [ID]`](#smartthings-invitesschemadelete-id) * [`smartthings locations [IDORINDEX]`](#smartthings-locations-idorindex) @@ -4157,45 +4156,6 @@ EXAMPLES _See code: [src/commands/invites/schema.ts](https://github.com/SmartThingsCommunity/smartthings-cli/blob/@smartthings/cli@1.8.0/packages/cli/src/commands/invites/schema.ts)_ -## `smartthings invites:schema:check-acceptance [ID]` - -check the acceptance status of a schema app invitation - -``` -USAGE - $ smartthings invites:schema:check-acceptance [ID] [-h] [-p ] [-t ] [--language ] [-j] [-y] [-o ] - [--schema-app ] - -ARGUMENTS - ID the invitation id - -FLAGS - --schema-app= schema app id - -COMMON FLAGS - -h, --help Show CLI help. - -j, --json use JSON format of input and/or output - -o, --output= specify output file - -p, --profile= [default: default] configuration profile - -t, --token= the auth token to use - -y, --yaml use YAML format of input and/or output - --language= ISO language code or "NONE" to not specify a language. Defaults to the OS locale - -DESCRIPTION - check the acceptance status of a schema app invitation - -EXAMPLES - prompt for an invitation and check its acceptance status - - $ smartthings invites:schema:check-acceptance - - check acceptance status for the specified invitation - - $ smartthings invites:schema:check-acceptance 7bd4c5b6-e840-44b3-9933-549a342d95ce -``` - -_See code: [src/commands/invites/schema/check-acceptance.ts](https://github.com/SmartThingsCommunity/smartthings-cli/blob/@smartthings/cli@1.8.0/packages/cli/src/commands/invites/schema/check-acceptance.ts)_ - ## `smartthings invites:schema:create` create an invitation to a schema app diff --git a/packages/cli/package.json b/packages/cli/package.json index a15852af..97281330 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -77,7 +77,7 @@ "@oclif/plugin-not-found": "^2.3.1", "@oclif/plugin-plugins": "^2.1.0", "@smartthings/cli-lib": "^2.2.2", - "@smartthings/core-sdk": "^8.1.0", + "@smartthings/core-sdk": "^8.1.1", "@smartthings/plugin-cli-edge": "^3.3.1", "inquirer": "^8.2.4", "js-yaml": "^4.1.0", diff --git a/packages/cli/src/__tests__/lib/commands/invites-util.test.ts b/packages/cli/src/__tests__/lib/commands/invites-util.test.ts index ee074132..9236dd9a 100644 --- a/packages/cli/src/__tests__/lib/commands/invites-util.test.ts +++ b/packages/cli/src/__tests__/lib/commands/invites-util.test.ts @@ -2,7 +2,7 @@ import { SchemaApp, SchemaAppInvitation, SmartThingsClient } from '@smartthings/ import { APICommand, ValueTableFieldDefinition, chooseOptionsWithDefaults, selectFromList, stringTranslateToId } from '@smartthings/cli-lib' -import { chooseSchemaInvitation, getSingleInvite, inviteTableFieldDefinitions } from '../../../lib/commands/invites-utils' +import { addAppDetails, chooseSchemaInvitation, getSingleInvite, tableFieldDefinitions } from '../../../lib/commands/invites-utils' import { chooseSchemaApp } from '../../../lib/commands/schema-util' @@ -74,41 +74,82 @@ describe('chooseSchemaInvitation', () => { }) test.each` - input | expected - ${undefined} | ${'none'} - ${1694617703} | ${'2023-09-13T15:08:23.000Z'} + input | expected + ${undefined} | ${'none'} + ${1694617703} | ${'2023-09-13T15:08:23.000Z'} `('expiration displays $expected for $input', ({ input, expected }) => { - const value = (inviteTableFieldDefinitions[2] as + const value = (tableFieldDefinitions[2] as ValueTableFieldDefinition).value as (input: SchemaAppInvitation) => string expect(value({ expiration: input } as SchemaAppInvitation)).toBe(expected) }) +describe('addAppDetails', () => { + it('handles optional fields', () => { + expect(addAppDetails({ + id: 'invitation-id', + schemaAppId: 'schema-app-id', + } as SchemaAppInvitation, { + } as SchemaApp)).toStrictEqual({ + id: 'invitation-id', + schemaAppId: 'schema-app-id', + schemaAppName: undefined, + sort: ':schema-app-id :invitation-id', + }) + }) + + it('handles populated optional fields', () => { + expect(addAppDetails({ + id: 'invitation-id', + description: 'invitation-description', + schemaAppId: 'schema-app-id', + } as SchemaAppInvitation, { + appName: 'schema-app-name', + } as SchemaApp)).toStrictEqual({ + id: 'invitation-id', + description: 'invitation-description', + schemaAppId: 'schema-app-id', + schemaAppName: 'schema-app-name', + sort: 'schema-app-name:schema-app-id invitation-description:invitation-id', + }) + }) +}) + describe('getSingleInvite', () => { const invitation1 = { id: 'invitation-id-1' } as SchemaAppInvitation - const invitation2 = { id: 'invitation-id-2' } as SchemaAppInvitation + const invitation2 = { id: 'invitation-id-2', schemaAppId: 'invite-2-app-id' } as SchemaAppInvitation const invitation3 = { id: 'invitation-id-3' } as SchemaAppInvitation const invitationList = [invitation1, invitation2, invitation3] const schemaApp1 = { endpointAppId: 'schema-app-id-1' } as SchemaApp - const schemaApp2 = { endpointAppId: 'schema-app-id-2' } as SchemaApp + const schemaApp2 = { endpointAppId: 'schema-app-id-2', appName: 'Schema App 2' } as SchemaApp const schemaApp3 = { endpointAppId: 'schema-app-id-3' } as SchemaApp const schemaAppList = [schemaApp1, schemaApp2, schemaApp3] const listInvitesMock = jest.fn().mockResolvedValue(invitationList) const listSchemaMock = jest.fn().mockResolvedValue(schemaAppList) + const getSchemaMock = jest.fn() const client = { invitesSchema: { list: listInvitesMock, }, schema: { + get: getSchemaMock, list: listSchemaMock, }, } as unknown as SmartThingsClient describe('with schemaAppId specified', () => { it('returns invitation with matching id', async () => { - expect(await getSingleInvite(client, 'schema-app-id', 'invitation-id-2')).toBe(invitation2) + getSchemaMock.mockResolvedValueOnce(schemaApp2) + + expect(await getSingleInvite(client, 'schema-app-id', 'invitation-id-2')).toStrictEqual({ + ...invitation2, + schemaAppName: 'Schema App 2', + sort: 'Schema App 2:invite-2-app-id :invitation-id-2', + }) + expect(getSchemaMock).toHaveBeenCalledTimes(1) + expect(getSchemaMock).toHaveBeenCalledWith('invite-2-app-id') expect(listInvitesMock).toHaveBeenCalledTimes(1) expect(listInvitesMock).toHaveBeenCalledWith('schema-app-id') @@ -118,24 +159,32 @@ describe('getSingleInvite', () => { it('throws an error when no matching invite found', async () => { await expect(getSingleInvite(client, 'schema-app-id', 'bad-invitation-id')).rejects.toThrow() - expect(listSchemaMock).toHaveBeenCalledTimes(0) expect(listInvitesMock).toHaveBeenCalledTimes(1) expect(listInvitesMock).toHaveBeenCalledWith('schema-app-id') + + expect(getSchemaMock).toHaveBeenCalledTimes(0) + expect(listSchemaMock).toHaveBeenCalledTimes(0) }) }) - describe('with schemaAppId specified', () => { + describe('with schemaAppId not specified', () => { it('searches schema apps when none specified', async () => { listInvitesMock.mockResolvedValueOnce([invitation1]) listInvitesMock.mockResolvedValueOnce([invitation3, invitation2]) - expect(await getSingleInvite(client, undefined, 'invitation-id-2')).toBe(invitation2) + expect(await getSingleInvite(client, undefined, 'invitation-id-2')).toStrictEqual({ + ...invitation2, + schemaAppName: 'Schema App 2', + sort: 'Schema App 2:invite-2-app-id :invitation-id-2', + }) expect(listSchemaMock).toHaveBeenCalledTimes(1) expect(listSchemaMock).toHaveBeenCalledWith() expect(listInvitesMock).toHaveBeenCalledTimes(2) expect(listInvitesMock).toHaveBeenCalledWith('schema-app-id-1') expect(listInvitesMock).toHaveBeenCalledWith('schema-app-id-2') + + expect(getSchemaMock).toHaveBeenCalledTimes(0) }) it('skips schema apps with no id', async () => { @@ -143,13 +192,19 @@ describe('getSingleInvite', () => { listInvitesMock.mockResolvedValueOnce([invitation1]) listInvitesMock.mockResolvedValueOnce([invitation3, invitation2]) - expect(await getSingleInvite(client, undefined, 'invitation-id-2')).toBe(invitation2) + expect(await getSingleInvite(client, undefined, 'invitation-id-2')).toStrictEqual({ + ...invitation2, + schemaAppName: 'Schema App 2', + sort: 'Schema App 2:invite-2-app-id :invitation-id-2', + }) expect(listSchemaMock).toHaveBeenCalledTimes(1) expect(listSchemaMock).toHaveBeenCalledWith() expect(listInvitesMock).toHaveBeenCalledTimes(2) expect(listInvitesMock).toHaveBeenCalledWith('schema-app-id-1') expect(listInvitesMock).toHaveBeenCalledWith('schema-app-id-2') + + expect(getSchemaMock).toHaveBeenCalledTimes(0) }) it('throws an error when no matching invite found', async () => { @@ -161,6 +216,8 @@ describe('getSingleInvite', () => { expect(listInvitesMock).toHaveBeenCalledWith('schema-app-id-1') expect(listInvitesMock).toHaveBeenCalledWith('schema-app-id-2') expect(listInvitesMock).toHaveBeenCalledWith('schema-app-id-3') + + expect(getSchemaMock).toHaveBeenCalledTimes(0) }) }) }) diff --git a/packages/cli/src/commands/invites/schema.ts b/packages/cli/src/commands/invites/schema.ts index 7b67d550..a56854a9 100644 --- a/packages/cli/src/commands/invites/schema.ts +++ b/packages/cli/src/commands/invites/schema.ts @@ -1,6 +1,6 @@ import { Flags } from '@oclif/core' -import { SchemaAppInvitation } from '@smartthings/core-sdk' +import { SmartThingsClient } from '@smartthings/core-sdk' import { APICommand, @@ -8,8 +8,7 @@ import { OutputItemOrListConfig, } from '@smartthings/cli-lib' -import { getSingleInvite, inviteTableFieldDefinitions } from '../../lib/commands/invites-utils' -import { chooseSchemaApp } from '../../lib/commands/schema-util' +import { addAppDetails, getSingleInvite, InvitationWithAppDetails, tableFieldDefinitions } from '../../lib/commands/invites-utils' export default class InvitesSchemaCommand extends APICommand { @@ -49,18 +48,29 @@ export default class InvitesSchemaCommand extends APICommand { - const config: OutputItemOrListConfig = { + type InvitationProviderFunction = () => Promise + const listFn = (client: SmartThingsClient, appId?: string): InvitationProviderFunction => + async (): Promise => { + const apps = appId + ? [await client.schema.get(appId)] + : await client.schema.list() + return (await Promise.all(apps.map(async app => { + return app.endpointAppId + ? (await client.invitesSchema.list(app.endpointAppId)) + .map(invite => addAppDetails(invite, app)) + : [] + }))).flat() + } + + const config: OutputItemOrListConfig = { primaryKeyName: 'id', - sortKeyName: 'description', + sortKeyName: 'sort', itemName: 'schema app invitation', - listTableFieldDefinitions: ['id', 'description', 'shortCode'], - tableFieldDefinitions: inviteTableFieldDefinitions, - } - const list = async (): Promise => { - const schemaAppId = await chooseSchemaApp(this, this.flags['schema-app']) - return this.client.invitesSchema.list(schemaAppId) + listTableFieldDefinitions: [{ prop: 'id', label: 'Invitation Id' }, 'schemaAppName', 'description'], + tableFieldDefinitions, } await outputItemOrList(this, config, this.args.idOrIndex, - list, id => getSingleInvite(this.client, this.flags['schema-app'], id)) + listFn(this.client, this.flags['schema-app']), + id => getSingleInvite(this.client, this.flags['schema-app'], id)) } } diff --git a/packages/cli/src/commands/invites/schema/check-acceptance.ts b/packages/cli/src/commands/invites/schema/check-acceptance.ts deleted file mode 100644 index fc690beb..00000000 --- a/packages/cli/src/commands/invites/schema/check-acceptance.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Flags } from '@oclif/core' - -import { APICommand, FormatAndWriteItemConfig, formatAndWriteItem } from '@smartthings/cli-lib' - -import { chooseSchemaInvitation } from '../../../lib/commands/invites-utils' -import { SchemaAppAcceptanceStatus } from '@smartthings/core-sdk' - - -export default class DeviceStatusCommand extends APICommand { - static description = 'check the acceptance status of a schema app invitation' - - static flags = { - ...APICommand.flags, - ...formatAndWriteItem.flags, - // eslint-disable-next-line @typescript-eslint/naming-convention - 'schema-app': Flags.string({ - description: 'schema app id', - }), - } - - static args = [{ - name: 'id', - description: 'the invitation id', - }] - - static examples = [ - { - description: 'prompt for an invitation and check its acceptance status', - command: 'smartthings invites:schema:check-acceptance', - }, - { - description: 'check acceptance status for the specified invitation', - command: 'smartthings invites:schema:check-acceptance 7bd4c5b6-e840-44b3-9933-549a342d95ce', - }, - ] - - async run(): Promise { - const id = await chooseSchemaInvitation(this, this.flags['schema-app'], this.args.idOrIndex) - const status = await this.client.invitesSchema.getAcceptanceStatus(id) - const config: FormatAndWriteItemConfig = { - tableFieldDefinitions: ['isAccepted', 'description', 'shortCode'], - } - await formatAndWriteItem(this, config, status) - } -} diff --git a/packages/cli/src/commands/invites/schema/create.ts b/packages/cli/src/commands/invites/schema/create.ts index bb554e30..85a87c4e 100644 --- a/packages/cli/src/commands/invites/schema/create.ts +++ b/packages/cli/src/commands/invites/schema/create.ts @@ -1,6 +1,6 @@ import { Flags } from '@oclif/core' -import { SchemaApp, SchemaAppInvitation, SchemaAppInvitationCreate } from '@smartthings/core-sdk' +import { SchemaApp, SchemaAppInvitationCreate } from '@smartthings/core-sdk' import { APICommand, @@ -15,7 +15,7 @@ import { } from '@smartthings/cli-lib' import { chooseSchemaApp } from '../../../lib/commands/schema-util' -import { getSingleInvite, inviteTableFieldDefinitions } from '../../../lib/commands/invites-utils' +import { getSingleInvite, InvitationWithAppDetails, tableFieldDefinitions } from '../../../lib/commands/invites-utils' export default class InvitesSchemaCreateCommand extends APICommand { @@ -86,11 +86,14 @@ export default class InvitesSchemaCreateCommand extends APICommand { - const createInvitation = async (_: unknown, input: SchemaAppInvitationCreate): Promise => { + const createInvitation = async (_: unknown, input: SchemaAppInvitationCreate): Promise => { + // We don't need the full schema app but we need to call this to force some + // bookkeeping in the back end for older apps. + await this.client.schema.get(input.schemaAppId) const idWrapper = await this.client.invitesSchema.create(input) return getSingleInvite(this.client, input.schemaAppId, idWrapper.invitationId) } - await inputAndOutputItem(this, - { tableFieldDefinitions: inviteTableFieldDefinitions }, createInvitation, userInputProcessor(this)) + await inputAndOutputItem(this, + { tableFieldDefinitions }, createInvitation, userInputProcessor(this)) } } diff --git a/packages/cli/src/lib/commands/invites-utils.ts b/packages/cli/src/lib/commands/invites-utils.ts index 1ffd4b1c..bf2848f3 100644 --- a/packages/cli/src/lib/commands/invites-utils.ts +++ b/packages/cli/src/lib/commands/invites-utils.ts @@ -1,4 +1,4 @@ -import { SchemaAppInvitation, SmartThingsClient } from '@smartthings/core-sdk' +import { SchemaApp, SchemaAppInvitation, SmartThingsClient } from '@smartthings/core-sdk' import { APICommand, @@ -29,29 +29,44 @@ export const chooseSchemaInvitation = async (command: APICommand[] = [ - 'id', +export type InvitationWithAppDetails = SchemaAppInvitation & { + schemaAppId?: string + schemaAppName?: string + sort: string +} + +export const tableFieldDefinitions: TableFieldDefinition[] = [ + { prop: 'id', label: 'Invitation Id' }, 'description', { label: 'Expiration', value: (invite) => invite.expiration ? new Date(invite.expiration * 1000).toISOString() : 'none', }, + 'acceptances', 'acceptUrl', - 'shortCode', + 'schemaAppId', + 'schemaAppName', ] +export const addAppDetails = (invite: SchemaAppInvitation, app: SchemaApp): InvitationWithAppDetails => ({ + ...invite, + schemaAppName: app.appName, + // In future we should make it so we can sort by multiple fields. + sort: `${app.appName ?? ''}:${invite.schemaAppId} ${invite.description ?? ''}:${invite.id}`, +}) + /** * Since there is no API to get a single invitation, this function uses the list function to get all * invites for a given schema app and then returns the one specified by the `id` parameter. */ -export const getSingleInvite = async (client: SmartThingsClient, schemaAppId: string | undefined, id: string): Promise => { +export const getSingleInvite = async (client: SmartThingsClient, schemaAppId: string | undefined, id: string): Promise => { const findInvitation = async (schemaAppId: string): Promise => (await client.invitesSchema.list(schemaAppId)).find(invite => invite.id === id) if (schemaAppId) { - const retVal = await findInvitation(schemaAppId) - if (retVal) { - return retVal + const invite = await findInvitation(schemaAppId) + if (invite) { + return addAppDetails(invite, await client.schema.get(invite.schemaAppId)) } } else { const schemaApps = await client.schema.list() @@ -59,9 +74,9 @@ export const getSingleInvite = async (client: SmartThingsClient, schemaAppId: st if (schemaApp.endpointAppId == null) { continue } - const retVal = await findInvitation(schemaApp.endpointAppId) - if (retVal) { - return retVal + const invite = await findInvitation(schemaApp.endpointAppId) + if (invite) { + return addAppDetails(invite, schemaApp) } } } diff --git a/packages/edge/package.json b/packages/edge/package.json index 9263394f..49997f17 100644 --- a/packages/edge/package.json +++ b/packages/edge/package.json @@ -48,7 +48,7 @@ "@log4js-node/log4js-api": "^1.0.2", "@oclif/core": "^1.16.3", "@smartthings/cli-lib": "^2.2.2", - "@smartthings/core-sdk": "^8.1.0", + "@smartthings/core-sdk": "^8.1.1", "axios": "^0.27.2", "inquirer": "^8.2.4", "js-yaml": "^4.1.0", diff --git a/packages/lib/package.json b/packages/lib/package.json index b3ae0a9a..45df93de 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -30,7 +30,7 @@ "dependencies": { "@log4js-node/log4js-api": "^1.0.2", "@oclif/core": "^1.16.3", - "@smartthings/core-sdk": "^8.1.0", + "@smartthings/core-sdk": "^8.1.1", "@types/eventsource": "^1.1.9", "axios": "^0.27.2", "chalk": "^4.1.2", diff --git a/packages/testlib/package.json b/packages/testlib/package.json index 6164a186..2a225900 100644 --- a/packages/testlib/package.json +++ b/packages/testlib/package.json @@ -29,7 +29,7 @@ }, "dependencies": { "@smartthings/cli-lib": "^2.2.2", - "@smartthings/core-sdk": "^8.1.0" + "@smartthings/core-sdk": "^8.1.1" }, "devDependencies": { "@types/jest": "^28.1.5",