From 25c4357b7a7d72e9cb86681a98e4a9eef62bfbce Mon Sep 17 00:00:00 2001 From: John Undersander <19363370+john-u@users.noreply.github.com> Date: Mon, 27 Jun 2022 16:02:14 -0500 Subject: [PATCH] feat(apps): update core-sdk app models --- .changeset/wet-cherries-wink.md | 7 ++++ package-lock.json | 24 ++++++------ packages/cli/package.json | 2 +- .../cli/src/__tests__/commands/apps.test.ts | 8 ++-- .../__tests__/commands/apps/create.test.ts | 39 +++++++------------ .../src/__tests__/commands/apps/oauth.test.ts | 4 +- .../commands/apps/oauth/generate.test.ts | 4 +- .../commands/apps/oauth/update.test.ts | 8 +++- .../__tests__/commands/apps/register.test.ts | 10 ++--- .../__tests__/commands/apps/settings.test.ts | 8 ++-- .../commands/apps/settings/update.test.ts | 4 +- .../__tests__/commands/apps/update.test.ts | 39 ++++++++----------- .../lib/commands/apps/apps-util.test.ts | 1 - packages/cli/src/commands/apps.ts | 6 +-- packages/cli/src/commands/apps/create.ts | 4 +- .../cli/src/commands/apps/oauth/generate.ts | 4 +- .../cli/src/commands/apps/oauth/update.ts | 4 +- packages/cli/src/commands/apps/register.ts | 11 +++--- packages/cli/src/commands/apps/settings.ts | 4 +- .../cli/src/commands/apps/settings/update.ts | 6 +-- packages/cli/src/commands/apps/update.ts | 6 +-- .../cli/src/lib/commands/apps/apps-util.ts | 14 +++---- packages/lib/package.json | 2 +- packages/testlib/package.json | 2 +- 24 files changed, 109 insertions(+), 112 deletions(-) create mode 100644 .changeset/wet-cherries-wink.md diff --git a/.changeset/wet-cherries-wink.md b/.changeset/wet-cherries-wink.md new file mode 100644 index 000000000..a58c516f7 --- /dev/null +++ b/.changeset/wet-cherries-wink.md @@ -0,0 +1,7 @@ +--- +"@smartthings/cli": patch +"@smartthings/cli-lib": patch +"@smartthings/cli-testlib": patch +--- + +update @smartthings/core-sdk to 5.0.0 diff --git a/package-lock.json b/package-lock.json index 19fc8bc0f..eaec30970 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3680,9 +3680,9 @@ "link": true }, "node_modules/@smartthings/core-sdk": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@smartthings/core-sdk/-/core-sdk-4.2.0.tgz", - "integrity": "sha512-quyFw2Ku2nyy2ifK3Hyy+0S4T5j2Tg4IVwKbtfOm/A9zfoi+hckNu4UA2aF/9NsGO5B226So5OvtUCAo9fCgjA==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@smartthings/core-sdk/-/core-sdk-5.0.0.tgz", + "integrity": "sha512-wY9ZkYKT0hn/aCtu69sTM0JRLJHylRd/j1i4kKcOCvkGdmYMB9wDXIrVE39j61E9hhvPlwXoxHhRsrsK8aFBGQ==", "dependencies": { "async-mutex": "^0.3.2", "axios": "^0.21.4", @@ -18357,7 +18357,7 @@ "@oclif/plugin-not-found": "^2.3.1", "@oclif/plugin-plugins": "^2.1.0", "@smartthings/cli-lib": "^1.0.0-beta.8", - "@smartthings/core-sdk": "^4.2.0", + "@smartthings/core-sdk": "^5.0.0", "@smartthings/plugin-cli-edge": "^1.14.1", "aws-sdk": "^2.1144.0", "cli-table": "^0.3.11", @@ -18402,7 +18402,7 @@ "dependencies": { "@log4js-node/log4js-api": "^1.0.2", "@oclif/core": "^1.9.0", - "@smartthings/core-sdk": "^4.2.0", + "@smartthings/core-sdk": "^5.0.0", "@types/eventsource": "^1.1.8", "axios": "^0.21.4", "chalk": "^4.1.2", @@ -18454,7 +18454,7 @@ "license": "Apache-2.0", "dependencies": { "@smartthings/cli-lib": "^1.0.0-beta.9", - "@smartthings/core-sdk": "^4.2.0" + "@smartthings/core-sdk": "^5.0.0" }, "devDependencies": { "@types/jest": "^28.1.3", @@ -21464,7 +21464,7 @@ "@oclif/plugin-plugins": "^2.1.0", "@smartthings/cli-lib": "^1.0.0-beta.8", "@smartthings/cli-testlib": "^1.0.0-beta.4", - "@smartthings/core-sdk": "^4.2.0", + "@smartthings/core-sdk": "^5.0.0", "@smartthings/plugin-cli-edge": "^1.14.1", "@types/cli-table": "^0.3.0", "@types/inquirer": "^8.2.1", @@ -21497,7 +21497,7 @@ "requires": { "@log4js-node/log4js-api": "^1.0.2", "@oclif/core": "^1.9.0", - "@smartthings/core-sdk": "^4.2.0", + "@smartthings/core-sdk": "^5.0.0", "@types/cli-table": "^0.3.0", "@types/eventsource": "^1.1.8", "@types/express": "^4.17.13", @@ -21541,7 +21541,7 @@ "version": "file:packages/testlib", "requires": { "@smartthings/cli-lib": "^1.0.0-beta.9", - "@smartthings/core-sdk": "^4.2.0", + "@smartthings/core-sdk": "^5.0.0", "@types/jest": "^28.1.3", "@types/js-yaml": "^4.0.5", "@types/node": "^16.11.41", @@ -21560,9 +21560,9 @@ } }, "@smartthings/core-sdk": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@smartthings/core-sdk/-/core-sdk-4.2.0.tgz", - "integrity": "sha512-quyFw2Ku2nyy2ifK3Hyy+0S4T5j2Tg4IVwKbtfOm/A9zfoi+hckNu4UA2aF/9NsGO5B226So5OvtUCAo9fCgjA==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@smartthings/core-sdk/-/core-sdk-5.0.0.tgz", + "integrity": "sha512-wY9ZkYKT0hn/aCtu69sTM0JRLJHylRd/j1i4kKcOCvkGdmYMB9wDXIrVE39j61E9hhvPlwXoxHhRsrsK8aFBGQ==", "requires": { "async-mutex": "^0.3.2", "axios": "^0.21.4", diff --git a/packages/cli/package.json b/packages/cli/package.json index eec21a780..bad2c06b7 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -72,7 +72,7 @@ "@oclif/plugin-not-found": "^2.3.1", "@oclif/plugin-plugins": "^2.1.0", "@smartthings/cli-lib": "^1.0.0-beta.8", - "@smartthings/core-sdk": "^4.2.0", + "@smartthings/core-sdk": "^5.0.0", "@smartthings/plugin-cli-edge": "^1.14.1", "aws-sdk": "^2.1144.0", "cli-table": "^0.3.11", diff --git a/packages/cli/src/__tests__/commands/apps.test.ts b/packages/cli/src/__tests__/commands/apps.test.ts index 394accec3..4f8983309 100644 --- a/packages/cli/src/__tests__/commands/apps.test.ts +++ b/packages/cli/src/__tests__/commands/apps.test.ts @@ -1,12 +1,12 @@ import { outputListing } from '@smartthings/cli-lib' -import { App, AppClassification, AppsEndpoint, AppType } from '@smartthings/core-sdk' +import { AppResponse, AppClassification, AppsEndpoint, AppType, PagedApp } from '@smartthings/core-sdk' import AppsCommand from '../../commands/apps' describe('AppsCommand', () => { const appId = 'appId' - const app: App = { appId: appId, webhookSmartApp: { targetUrl: 'targetUrl' } } - const appList = [app] + const app = { appId: appId, webhookSmartApp: { targetUrl: 'targetUrl' } } as AppResponse + const appList = [{ appId: appId }] as PagedApp[] const mockOutputListing = jest.mocked(outputListing) const getSpy = jest.spyOn(AppsEndpoint.prototype, 'get').mockImplementation() const listSpy = jest.spyOn(AppsEndpoint.prototype, 'list').mockImplementation() @@ -143,7 +143,7 @@ describe('AppsCommand', () => { await expect(AppsCommand.run(['--verbose'])).resolves.not.toThrow() const listApps = mockOutputListing.mock.calls[0][3] - const verboseApp = (await listApps()).pop() as App & { 'ARN/URL'?: string } + const verboseApp = (await listApps()).pop() as AppResponse & { 'ARN/URL'?: string } expect(getSpy).toBeCalledTimes(1) expect(getSpy).toBeCalledWith(appId) diff --git a/packages/cli/src/__tests__/commands/apps/create.test.ts b/packages/cli/src/__tests__/commands/apps/create.test.ts index 90e506de2..971cbdb83 100644 --- a/packages/cli/src/__tests__/commands/apps/create.test.ts +++ b/packages/cli/src/__tests__/commands/apps/create.test.ts @@ -1,5 +1,5 @@ import { CustomCommonOutputProducer, DefaultTableGenerator, inputAndOutputItem } from '@smartthings/cli-lib' -import { AppCreationResponse, AppRequest, AppsEndpoint } from '@smartthings/core-sdk' +import { AppCreationResponse, AppCreateRequest, AppsEndpoint, AppResponse } from '@smartthings/core-sdk' import AppCreateCommand from '../../../commands/apps/create' import { tableFieldDefinitions } from '../../../lib/commands/apps/apps-util' import { addPermission } from '../../../lib/aws-utils' @@ -15,7 +15,7 @@ describe('AppCreateCommand', () => { it('calls inputOutput with correct config', async () => { const appCreate: AppCreationResponse = { - app: {}, + app: { appName: 'app ' } as AppResponse, oauthClientId: 'oauthClientId', oauthClientSecret: 'oauthClientSecret', } @@ -37,7 +37,7 @@ describe('AppCreateCommand', () => { }) it('calls correct create endpoint', async () => { - const appRequest: AppRequest = {} + const appRequest = { appName: 'app' } as AppCreateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -50,11 +50,11 @@ describe('AppCreateCommand', () => { it('accepts authorize flag for lambda apps', async () => { const arn = 'arn' const anotherArn = 'anotherArn' - const appRequest: AppRequest = { + const appRequest = { lambdaSmartApp: { functions: [arn, anotherArn], }, - } + } as AppCreateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -68,9 +68,9 @@ describe('AppCreateCommand', () => { }) it('throws error if authorize flag is used on non-lambda app', async () => { - const appRequest: AppRequest = { + const appRequest = { webhookSmartApp: {}, - } + } as AppCreateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -80,11 +80,11 @@ describe('AppCreateCommand', () => { }) it('ignores authorize flag for lambda apps with no functions', async () => { - let appRequest: AppRequest = { + const appRequest = { lambdaSmartApp: { functions: [], }, - } + } as unknown as AppCreateRequest mockInputAndOutputItem.mockImplementation(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -95,24 +95,15 @@ describe('AppCreateCommand', () => { expect(createSpy).toBeCalledWith(appRequest) createSpy.mockClear() - - appRequest = { - lambdaSmartApp: {}, - } - - await expect(AppCreateCommand.run(['--authorize'])).resolves.not.toThrow() - - expect(addPermission).not.toBeCalled() - expect(createSpy).toBeCalledWith(appRequest) }) it('calls addPermission with principal flag', async () => { const arn = 'arn' - const appRequest: AppRequest = { + const appRequest = { lambdaSmartApp: { functions: [arn], }, - } + } as AppCreateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -125,11 +116,11 @@ describe('AppCreateCommand', () => { it('calls addPermission with statement-id flag', async () => { const arn = 'arn' - const appRequest: AppRequest = { + const appRequest = { lambdaSmartApp: { functions: [arn], }, - } + } as AppCreateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -142,11 +133,11 @@ describe('AppCreateCommand', () => { it('ignores already authorized functions', async () => { const arn = 'arn' - const appRequest: AppRequest = { + const appRequest = { lambdaSmartApp: { functions: [arn], }, - } + } as AppCreateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) diff --git a/packages/cli/src/__tests__/commands/apps/oauth.test.ts b/packages/cli/src/__tests__/commands/apps/oauth.test.ts index b8b4043d9..437b2f4ab 100644 --- a/packages/cli/src/__tests__/commands/apps/oauth.test.ts +++ b/packages/cli/src/__tests__/commands/apps/oauth.test.ts @@ -1,5 +1,5 @@ import { outputItem } from '@smartthings/cli-lib' -import { AppOAuth, AppsEndpoint } from '@smartthings/core-sdk' +import { AppOAuthResponse, AppsEndpoint } from '@smartthings/core-sdk' import AppOauthCommand from '../../../commands/apps/oauth' import { chooseApp } from '../../../lib/commands/apps/apps-util' @@ -40,7 +40,7 @@ describe('AppOauthCommand', () => { it('uses correct endpoint to get oauth details', async () => { const appId = 'appId' mockChooseApp.mockResolvedValueOnce(appId) - const appOAuth: AppOAuth = { clientName: 'test' } + const appOAuth = { clientName: 'test' } as AppOAuthResponse getOauthSpy.mockResolvedValueOnce(appOAuth) mockOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { return actionFunction() diff --git a/packages/cli/src/__tests__/commands/apps/oauth/generate.test.ts b/packages/cli/src/__tests__/commands/apps/oauth/generate.test.ts index 407eb9fb0..77a507d93 100644 --- a/packages/cli/src/__tests__/commands/apps/oauth/generate.test.ts +++ b/packages/cli/src/__tests__/commands/apps/oauth/generate.test.ts @@ -1,5 +1,5 @@ import { inputAndOutputItem } from '@smartthings/cli-lib' -import { AppOAuth, AppsEndpoint } from '@smartthings/core-sdk' +import { GenerateAppOAuthRequest, AppsEndpoint } from '@smartthings/core-sdk' import AppOauthGenerateCommand from '../../../../commands/apps/oauth/generate' import { chooseApp } from '../../../../lib/commands/apps/apps-util' @@ -35,7 +35,7 @@ describe('AppOauthGenerateCommand', () => { it('uses correct endpoint to generate oauth', async () => { const appId = 'appId' - const oAuth: AppOAuth = { clientName: 'test' } + const oAuth = { clientName: 'test' } as GenerateAppOAuthRequest mockChooseApp.mockResolvedValueOnce(appId) mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, oAuth) diff --git a/packages/cli/src/__tests__/commands/apps/oauth/update.test.ts b/packages/cli/src/__tests__/commands/apps/oauth/update.test.ts index 1259de8dd..33e580518 100644 --- a/packages/cli/src/__tests__/commands/apps/oauth/update.test.ts +++ b/packages/cli/src/__tests__/commands/apps/oauth/update.test.ts @@ -1,5 +1,5 @@ import { inputAndOutputItem } from '@smartthings/cli-lib' -import { AppOAuth, AppsEndpoint } from '@smartthings/core-sdk' +import { AppOAuthRequest, AppsEndpoint } from '@smartthings/core-sdk' import AppOauthUpdateCommand from '../../../../commands/apps/oauth/update' import { chooseApp } from '../../../../lib/commands/apps/apps-util' @@ -23,7 +23,11 @@ describe('AppOauthUpdateCommand', () => { it('uses correct endpoint to update oauth', async () => { const appId = 'appId' - const oAuth: AppOAuth = { clientName: 'test' } + const oAuth: AppOAuthRequest = { + clientName: 'test', + redirectUris: [], + scope: [], + } mockChooseApp.mockResolvedValueOnce(appId) mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, oAuth) diff --git a/packages/cli/src/__tests__/commands/apps/register.test.ts b/packages/cli/src/__tests__/commands/apps/register.test.ts index b4d845438..1df629ae8 100644 --- a/packages/cli/src/__tests__/commands/apps/register.test.ts +++ b/packages/cli/src/__tests__/commands/apps/register.test.ts @@ -1,11 +1,11 @@ import { selectFromList } from '@smartthings/cli-lib' -import { App, AppsEndpoint, AppType } from '@smartthings/core-sdk' +import { PagedApp, AppsEndpoint, AppType } from '@smartthings/core-sdk' import AppRegisterCommand from '../../../commands/apps/register' describe('AppRegisterCommand', () => { const appId = 'appId' - const registerSpy = jest.spyOn(AppsEndpoint.prototype, 'register').mockResolvedValue({ status: '200' }) + const registerSpy = jest.spyOn(AppsEndpoint.prototype, 'register').mockResolvedValue() const listSpy = jest.spyOn(AppsEndpoint.prototype, 'list').mockImplementation() const logSpy = jest.spyOn(AppRegisterCommand.prototype, 'log').mockImplementation() const mockSelectFromList = jest.mocked(selectFromList) @@ -41,10 +41,10 @@ describe('AppRegisterCommand', () => { }) it('lists all app types that support registration', async () => { - const webhookApps: App[] = [{ appType: AppType.WEBHOOK_SMART_APP, webhookSmartApp: {} }] - const apiOnlyApps: App[] = [{ appType: AppType.API_ONLY, apiOnly: {} }] + const webhookApps = [{ appType: AppType.WEBHOOK_SMART_APP }] as PagedApp[] + const apiOnlyApps = [{ appType: AppType.API_ONLY }] as PagedApp[] listSpy.mockImplementation(async (options) => { - let apps: App[] = [] + let apps: PagedApp[] = [] if (options?.appType == AppType.WEBHOOK_SMART_APP) { apps = webhookApps } else if (options?.appType == AppType.API_ONLY) { diff --git a/packages/cli/src/__tests__/commands/apps/settings.test.ts b/packages/cli/src/__tests__/commands/apps/settings.test.ts index 6cab4034f..4d717cfac 100644 --- a/packages/cli/src/__tests__/commands/apps/settings.test.ts +++ b/packages/cli/src/__tests__/commands/apps/settings.test.ts @@ -1,5 +1,5 @@ import { CustomCommonOutputProducer, DefaultTableGenerator, outputItem } from '@smartthings/cli-lib' -import { AppsEndpoint, AppSettings } from '@smartthings/core-sdk' +import { AppsEndpoint, AppSettingsResponse } from '@smartthings/core-sdk' import AppSettingsCommand from '../../../commands/apps/settings' import { buildTableOutput, chooseApp } from '../../../lib/commands/apps/apps-util' @@ -11,7 +11,9 @@ describe('AppSettingsCommand', () => { const mockChooseApp = jest.mocked(chooseApp) const mockOutputItem = jest.mocked(outputItem) const settingsSpy = jest.spyOn(AppsEndpoint.prototype, 'getSettings').mockImplementation() - const appSettings: AppSettings = {} + const appSettings: AppSettingsResponse = { + settings: {}, + } beforeAll(() => { mockChooseApp.mockResolvedValue(appId) @@ -30,7 +32,7 @@ describe('AppSettingsCommand', () => { it('calls outputItem with correct config', async () => { mockOutputItem.mockImplementationOnce(async (_command, config) => { - (config as CustomCommonOutputProducer).buildTableOutput(appSettings) + (config as CustomCommonOutputProducer).buildTableOutput(appSettings) return appSettings }) diff --git a/packages/cli/src/__tests__/commands/apps/settings/update.test.ts b/packages/cli/src/__tests__/commands/apps/settings/update.test.ts index 57e1ee245..59ff9c629 100644 --- a/packages/cli/src/__tests__/commands/apps/settings/update.test.ts +++ b/packages/cli/src/__tests__/commands/apps/settings/update.test.ts @@ -1,5 +1,5 @@ import { inputAndOutputItem } from '@smartthings/cli-lib' -import { AppsEndpoint, AppSettings } from '@smartthings/core-sdk' +import { AppsEndpoint, AppSettingsRequest } from '@smartthings/core-sdk' import AppSettingsUpdateCommand from '../../../../commands/apps/settings/update' import { chooseApp } from '../../../../lib/commands/apps/apps-util' @@ -23,7 +23,7 @@ describe('AppSettingsUpdateCommand', () => { it('uses correct endpoint to update settings', async () => { const appId = 'appId' - const settings: AppSettings = {} + const settings: AppSettingsRequest = {} mockChooseApp.mockResolvedValueOnce(appId) mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, settings) diff --git a/packages/cli/src/__tests__/commands/apps/update.test.ts b/packages/cli/src/__tests__/commands/apps/update.test.ts index 9bb6e3649..1a4ee6db9 100644 --- a/packages/cli/src/__tests__/commands/apps/update.test.ts +++ b/packages/cli/src/__tests__/commands/apps/update.test.ts @@ -1,5 +1,5 @@ import { inputAndOutputItem } from '@smartthings/cli-lib' -import { AppRequest, AppsEndpoint } from '@smartthings/core-sdk' +import { AppUpdateRequest, AppsEndpoint } from '@smartthings/core-sdk' import AppUpdateCommand from '../../../commands/apps/update' import { chooseApp, tableFieldDefinitions } from '../../../lib/commands/apps/apps-util' import { addPermission } from '../../../lib/aws-utils' @@ -42,7 +42,9 @@ describe('AppUpdateCommand', () => { }) it('calls correct update endpoint', async () => { - const appRequest: AppRequest = {} + const appRequest = { + displayName: 'app', + } as AppUpdateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -56,11 +58,11 @@ describe('AppUpdateCommand', () => { it('accepts authorize flag for lambda apps', async () => { const arn = 'arn' const anotherArn = 'anotherArn' - const appRequest: AppRequest = { + const appRequest = { lambdaSmartApp: { functions: [arn, anotherArn], }, - } + } as AppUpdateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -75,9 +77,9 @@ describe('AppUpdateCommand', () => { }) it('throws error if authorize flag is used on non-lambda app', async () => { - const appRequest: AppRequest = { + const appRequest = { webhookSmartApp: {}, - } + } as AppUpdateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -87,11 +89,11 @@ describe('AppUpdateCommand', () => { }) it('ignores authorize flag for lambda apps with no functions', async () => { - let appRequest: AppRequest = { + const appRequest = { lambdaSmartApp: { functions: [], }, - } + } as unknown as AppUpdateRequest mockInputAndOutputItem.mockImplementation(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -103,24 +105,15 @@ describe('AppUpdateCommand', () => { expect(updateSpy).toBeCalledWith(appId, appRequest) updateSpy.mockClear() - - appRequest = { - lambdaSmartApp: {}, - } - - await expect(AppUpdateCommand.run([appId, '--authorize'])).resolves.not.toThrow() - - expect(addPermission).not.toBeCalled() - expect(updateSpy).toBeCalledWith(appId, appRequest) }) it('calls addPermission with principal flag', async () => { const arn = 'arn' - const appRequest: AppRequest = { + const appRequest = { lambdaSmartApp: { functions: [arn], }, - } + } as AppUpdateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -133,11 +126,11 @@ describe('AppUpdateCommand', () => { it('calls addPermission with statement-id flag', async () => { const arn = 'arn' - const appRequest: AppRequest = { + const appRequest: AppUpdateRequest = { lambdaSmartApp: { functions: [arn], }, - } + } as AppUpdateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) @@ -150,11 +143,11 @@ describe('AppUpdateCommand', () => { it('ignores already authorized functions', async () => { const arn = 'arn' - const appRequest: AppRequest = { + const appRequest: AppUpdateRequest = { lambdaSmartApp: { functions: [arn], }, - } + } as AppUpdateRequest mockInputAndOutputItem.mockImplementationOnce(async (_command, _config, actionFunction) => { await actionFunction(undefined, appRequest) }) diff --git a/packages/cli/src/__tests__/lib/commands/apps/apps-util.test.ts b/packages/cli/src/__tests__/lib/commands/apps/apps-util.test.ts index 63cafaa6d..457302272 100644 --- a/packages/cli/src/__tests__/lib/commands/apps/apps-util.test.ts +++ b/packages/cli/src/__tests__/lib/commands/apps/apps-util.test.ts @@ -122,7 +122,6 @@ describe('buildTableOutput', () => { buildTableFromList: jest.fn(), } it('returns simple string when app settings are not present', () => { - expect(buildTableOutput(mockTableGenerator, {})).toBe('No application settings.') expect(buildTableOutput(mockTableGenerator, { settings: {} })).toBe('No application settings.') }) diff --git a/packages/cli/src/commands/apps.ts b/packages/cli/src/commands/apps.ts index 3d2a2e5ca..79a34a9bd 100644 --- a/packages/cli/src/commands/apps.ts +++ b/packages/cli/src/commands/apps.ts @@ -1,5 +1,5 @@ import { Flags } from '@oclif/core' -import { App, AppType, AppClassification, AppListOptions } from '@smartthings/core-sdk' +import { AppType, AppClassification, AppListOptions, PagedApp, AppResponse } from '@smartthings/core-sdk' import { APICommand, outputListing } from '@smartthings/cli-lib' import { tableFieldDefinitions } from '../lib/commands/apps/apps-util' @@ -41,7 +41,7 @@ export default class AppsCommand extends APICommand { config.listTableFieldDefinitions.push('ARN/URL') } - const listApps = async (): Promise => { + const listApps = async (): Promise => { const appListOptions: AppListOptions = {} if (this.flags.type) { appListOptions.appType = AppType[this.flags.type as keyof typeof AppType] @@ -58,7 +58,7 @@ export default class AppsCommand extends APICommand { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return this.client.apps.get(app.appId!) }) - return Promise.all(apps).then((list: (App & { 'ARN/URL'?: string })[]) => { + return Promise.all(apps).then((list: (AppResponse & { 'ARN/URL'?: string })[]) => { for (const app of list) { const uri = (app.webhookSmartApp ? app.webhookSmartApp.targetUrl : diff --git a/packages/cli/src/commands/apps/create.ts b/packages/cli/src/commands/apps/create.ts index 4ddc26aec..c1037bb15 100644 --- a/packages/cli/src/commands/apps/create.ts +++ b/packages/cli/src/commands/apps/create.ts @@ -1,5 +1,5 @@ import { Flags, Errors } from '@oclif/core' -import { AppRequest, AppCreationResponse } from '@smartthings/core-sdk' +import { AppCreateRequest, AppCreationResponse } from '@smartthings/core-sdk' import { APICommand, inputAndOutputItem, lambdaAuthFlags } from '@smartthings/cli-lib' import { addPermission } from '../../lib/aws-utils' import { tableFieldDefinitions } from '../../lib/commands/apps/apps-util' @@ -18,7 +18,7 @@ export default class AppCreateCommand extends APICommand { - const createApp = async (_: void, data: AppRequest): Promise => { + const createApp = async (_: void, data: AppCreateRequest): Promise => { // TODO extract this authorization block out to util function and use in ./update.ts as well if (this.flags.authorize) { if (data.lambdaSmartApp) { diff --git a/packages/cli/src/commands/apps/oauth/generate.ts b/packages/cli/src/commands/apps/oauth/generate.ts index 422cc770c..464a40240 100644 --- a/packages/cli/src/commands/apps/oauth/generate.ts +++ b/packages/cli/src/commands/apps/oauth/generate.ts @@ -1,4 +1,4 @@ -import { AppOAuth } from '@smartthings/core-sdk' +import { GenerateAppOAuthRequest } from '@smartthings/core-sdk' import { APICommand, inputAndOutputItem } from '@smartthings/cli-lib' import { chooseApp, oauthTableFieldDefinitions } from '../../../lib/commands/apps/apps-util' @@ -20,6 +20,6 @@ export default class AppOauthGenerateCommand extends APICommand this.client.apps.regenerateOauth(appId, data)) + (_, data: GenerateAppOAuthRequest) => this.client.apps.regenerateOauth(appId, data)) } } diff --git a/packages/cli/src/commands/apps/oauth/update.ts b/packages/cli/src/commands/apps/oauth/update.ts index 6aa2200a8..9331a70c4 100644 --- a/packages/cli/src/commands/apps/oauth/update.ts +++ b/packages/cli/src/commands/apps/oauth/update.ts @@ -1,4 +1,4 @@ -import { AppOAuth } from '@smartthings/core-sdk' +import { AppOAuthRequest } from '@smartthings/core-sdk' import { APICommand, inputAndOutputItem } from '@smartthings/cli-lib' import { chooseApp, oauthTableFieldDefinitions } from '../../../lib/commands/apps/apps-util' @@ -19,6 +19,6 @@ export default class AppOauthUpdateCommand extends APICommand { const appId = await chooseApp(this, this.args.id) await inputAndOutputItem(this, { tableFieldDefinitions: oauthTableFieldDefinitions }, - (_, data: AppOAuth) => this.client.apps.updateOauth(appId, data)) + (_, data: AppOAuthRequest) => this.client.apps.updateOauth(appId, data)) } } diff --git a/packages/cli/src/commands/apps/register.ts b/packages/cli/src/commands/apps/register.ts index dec5ceccb..adc5e391e 100644 --- a/packages/cli/src/commands/apps/register.ts +++ b/packages/cli/src/commands/apps/register.ts @@ -1,5 +1,6 @@ -import { App, AppType } from '@smartthings/core-sdk' +import { AppType, PagedApp } from '@smartthings/core-sdk' import { APICommand, selectFromList, SelectingConfig } from '@smartthings/cli-lib' +import { inspect } from 'util' export default class AppRegisterCommand extends APICommand { @@ -13,12 +14,12 @@ export default class AppRegisterCommand extends APICommand { - const config: SelectingConfig = { + const config: SelectingConfig = { primaryKeyName: 'appId', sortKeyName: 'displayName', listTableFieldDefinitions: ['displayName', 'appType', 'appId'], } - const id = await selectFromList(this, config, { + const id = await selectFromList(this, config, { preselectedId: this.args.id, listItems: async () => (await Promise.all([ this.client.apps.list({ appType: AppType.WEBHOOK_SMART_APP }), @@ -26,7 +27,7 @@ export default class AppRegisterCommand extends APICommand { const id = await chooseApp(this, this.args.id, { allowIndex: true }) - const config: CustomCommonOutputProducer = + const config: CustomCommonOutputProducer = { buildTableOutput: appSettings => buildTableOutput(this.tableGenerator, appSettings) } await outputItem(this, config, () => this.client.apps.getSettings(id)) diff --git a/packages/cli/src/commands/apps/settings/update.ts b/packages/cli/src/commands/apps/settings/update.ts index a66c1166d..22994a0fb 100644 --- a/packages/cli/src/commands/apps/settings/update.ts +++ b/packages/cli/src/commands/apps/settings/update.ts @@ -1,4 +1,4 @@ -import { AppSettings } from '@smartthings/core-sdk' +import { AppSettingsRequest, AppSettingsResponse } from '@smartthings/core-sdk' import { APICommand, inputAndOutputItem } from '@smartthings/cli-lib' import { buildTableOutput, chooseApp } from '../../../lib/commands/apps/apps-util' @@ -19,7 +19,7 @@ export default class AppSettingsUpdateCommand extends APICommand { const appId = await chooseApp(this, this.args.id) await inputAndOutputItem(this, - { buildTableOutput: (data: AppSettings) => buildTableOutput(this.tableGenerator, data) }, - (_, data: AppSettings) => this.client.apps.updateSettings(appId, data)) + { buildTableOutput: (data: AppSettingsResponse) => buildTableOutput(this.tableGenerator, data) }, + (_, data: AppSettingsRequest) => this.client.apps.updateSettings(appId, data)) } } diff --git a/packages/cli/src/commands/apps/update.ts b/packages/cli/src/commands/apps/update.ts index 088769415..8cbd6ffcc 100644 --- a/packages/cli/src/commands/apps/update.ts +++ b/packages/cli/src/commands/apps/update.ts @@ -1,5 +1,5 @@ import { Flags } from '@oclif/core' -import { App, AppRequest } from '@smartthings/core-sdk' +import { AppUpdateRequest, AppResponse } from '@smartthings/core-sdk' import { ActionFunction, APICommand, inputAndOutputItem, TableCommonOutputProducer, lambdaAuthFlags } from '@smartthings/cli-lib' import { addPermission } from '../../lib/aws-utils' import { chooseApp, tableFieldDefinitions } from '../../lib/commands/apps/apps-util' @@ -25,7 +25,7 @@ export default class AppUpdateCommand extends APICommand { const appId = await chooseApp(this, this.args.id) - const executeUpdate: ActionFunction = async (_, data) => { + const executeUpdate: ActionFunction = async (_, data) => { if (this.flags.authorize) { if (data.lambdaSmartApp) { if (data.lambdaSmartApp.functions) { @@ -41,7 +41,7 @@ export default class AppUpdateCommand extends APICommand = { tableFieldDefinitions } + const config: TableCommonOutputProducer = { tableFieldDefinitions } await inputAndOutputItem(this, config, executeUpdate) } } diff --git a/packages/cli/src/lib/commands/apps/apps-util.ts b/packages/cli/src/lib/commands/apps/apps-util.ts index e9431f0d2..354f16bc4 100644 --- a/packages/cli/src/lib/commands/apps/apps-util.ts +++ b/packages/cli/src/lib/commands/apps/apps-util.ts @@ -1,11 +1,11 @@ import { APICommand, ChooseOptions, chooseOptionsWithDefaults, selectFromList, SelectingConfig, stringTranslateToId, TableFieldDefinition, TableGenerator } from '@smartthings/cli-lib' -import { App, AppSettings } from '@smartthings/core-sdk' +import { AppResponse, AppSettingsResponse, PagedApp } from '@smartthings/core-sdk' -const isWebhookSmartApp = (app: App): boolean => !!app.webhookSmartApp -const hasSubscription = (app: App): boolean => !!app.apiOnly?.subscription +const isWebhookSmartApp = (app: AppResponse): boolean => !!app.webhookSmartApp +const hasSubscription = (app: AppResponse): boolean => !!app.apiOnly?.subscription -export const tableFieldDefinitions: TableFieldDefinition[] = [ +export const tableFieldDefinitions: TableFieldDefinition[] = [ 'displayName', 'appId', 'appName', @@ -37,19 +37,19 @@ export const oauthTableFieldDefinitions = ['clientName', 'scope', 'redirectUris' export async function chooseApp(command: APICommand, appFromArg?: string, options?: Partial): Promise { const opts = chooseOptionsWithDefaults(options) - const config: SelectingConfig = { + const config: SelectingConfig = { itemName: 'app', primaryKeyName: 'appId', sortKeyName: 'displayName', } - const listItems = (): Promise => command.client.apps.list() + const listItems = (): Promise => command.client.apps.list() const preselectedId = opts.allowIndex ? await stringTranslateToId(config, appFromArg, listItems) : appFromArg return selectFromList(command, config, { preselectedId, listItems }) } -export function buildTableOutput(tableGenerator: TableGenerator, appSettings: AppSettings): string { +export function buildTableOutput(tableGenerator: TableGenerator, appSettings: AppSettingsResponse): string { if (!appSettings.settings || Object.keys(appSettings.settings).length === 0) { return 'No application settings.' } diff --git a/packages/lib/package.json b/packages/lib/package.json index 77ae9ca60..8f5bc7037 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.9.0", - "@smartthings/core-sdk": "^4.2.0", + "@smartthings/core-sdk": "^5.0.0", "@types/eventsource": "^1.1.8", "axios": "^0.21.4", "chalk": "^4.1.2", diff --git a/packages/testlib/package.json b/packages/testlib/package.json index 4d588339e..e51143437 100644 --- a/packages/testlib/package.json +++ b/packages/testlib/package.json @@ -29,7 +29,7 @@ }, "dependencies": { "@smartthings/cli-lib": "^1.0.0-beta.9", - "@smartthings/core-sdk": "^4.2.0" + "@smartthings/core-sdk": "^5.0.0" }, "devDependencies": { "@types/jest": "^28.1.3",