Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added organizations to Schema CRUD commands #549

Merged
merged 1 commit into from
Sep 28, 2023
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
8 changes: 8 additions & 0 deletions .changeset/early-houses-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@smartthings/cli-lib": patch
"@smartthings/cli-testlib": patch
"@smartthings/plugin-cli-edge": patch
"@smartthings/cli": patch
---

feat: added organizations to Schema CRUD commands
28 changes: 14 additions & 14 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@oclif/plugin-not-found": "^2.3.1",
"@oclif/plugin-plugins": "^2.1.0",
"@smartthings/cli-lib": "^2.2.1",
"@smartthings/core-sdk": "^8.0.0",
"@smartthings/core-sdk": "^8.0.1",
"@smartthings/plugin-cli-edge": "^3.3.0",
"inquirer": "^8.2.4",
"js-yaml": "^4.1.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/__tests__/commands/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ describe('SchemaCommand', () => {
expect.any(SchemaCommand),
expect.objectContaining({
tableFieldDefinitions: [
'appName', 'partnerName', 'endpointAppId', 'schemaType', 'hostingType',
'stClientId', 'oAuthAuthorizationUrl', 'oAuthTokenUrl', 'oAuthClientId',
'appName', 'partnerName', 'endpointAppId', 'organizationId', 'schemaType', 'hostingType',
('stClientId' as keyof SchemaApp), 'oAuthAuthorizationUrl', 'oAuthTokenUrl', 'oAuthClientId',
'oAuthClientSecret', 'icon', 'icon2x', 'icon3x',
{ prop: 'lambdaArn', skipEmpty: true },
{ prop: 'lambdaArnAP', skipEmpty: true },
Expand All @@ -31,7 +31,7 @@ describe('SchemaCommand', () => {
],
primaryKeyName: 'endpointAppId',
sortKeyName: 'appName',
listTableFieldDefinitions: ['appName', 'endpointAppId', 'hostingType'],
listTableFieldDefinitions: ['appName', 'endpointAppId', 'organizationId', 'hostingType'],
}),
'schemaAppId',
expect.any(Function),
Expand All @@ -58,7 +58,7 @@ describe('SchemaCommand', () => {
await expect(SchemaCommand.run(['--verbose'])).resolves.not.toThrow()

const config = (outputItemOrListMock.mock.calls[0][1] as TableCommonListOutputProducer<SchemaApp>)
const tableFieldDefinition = config.listTableFieldDefinitions[3] as { value: (input: SchemaApp) => string | undefined }
const tableFieldDefinition = config.listTableFieldDefinitions[4] as { value: (input: SchemaApp) => string | undefined }

expect(tableFieldDefinition).toBeObject()
const valueFunction = tableFieldDefinition.value
Expand Down
16 changes: 11 additions & 5 deletions packages/cli/src/commands/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ import { Flags } from '@oclif/core'

import { SchemaApp } from '@smartthings/core-sdk'

import { APICommand, outputItemOrList, OutputItemOrListConfig } from '@smartthings/cli-lib'
import {
allOrganizationsFlags,
APIOrganizationCommand,
outputItemOrList,
OutputItemOrListConfig,
} from '@smartthings/cli-lib'


export default class SchemaCommand extends APICommand<typeof SchemaCommand.flags> {
export default class SchemaCommand extends APIOrganizationCommand<typeof SchemaCommand.flags> {
static description = 'list all ST Schema Apps currently available in a user account' +
this.apiDocsURL('getAppsByUserToken', 'getAppsByEndpointAppId')

static flags = {
...APICommand.flags,
...APIOrganizationCommand.flags,
...outputItemOrList.flags,
...allOrganizationsFlags,
verbose: Flags.boolean({
description: 'include ARN in output',
char: 'v',
Expand All @@ -26,7 +32,7 @@ export default class SchemaCommand extends APICommand<typeof SchemaCommand.flags
async run(): Promise<void> {
const config: OutputItemOrListConfig<SchemaApp> = {
tableFieldDefinitions: [
'appName', 'partnerName', 'endpointAppId', 'schemaType', 'hostingType',
'appName', 'partnerName', 'endpointAppId', 'organizationId', 'schemaType', 'hostingType',
// stClientId is missing from the docs
('stClientId' as keyof SchemaApp), 'oAuthAuthorizationUrl', 'oAuthTokenUrl', 'oAuthClientId',
'oAuthClientSecret', 'icon', 'icon2x', 'icon3x',
Expand All @@ -39,7 +45,7 @@ export default class SchemaCommand extends APICommand<typeof SchemaCommand.flags
],
primaryKeyName: 'endpointAppId',
sortKeyName: 'appName',
listTableFieldDefinitions: ['appName', 'endpointAppId', 'hostingType'],
listTableFieldDefinitions: ['appName', 'endpointAppId', 'organizationId', 'hostingType'],
}
if (this.flags.verbose) {
config.listTableFieldDefinitions.push({
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/schema/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Flags } from '@oclif/core'
import { SchemaAppRequest, SchemaCreateResponse } from '@smartthings/core-sdk'

import {
APICommand,
APIOrganizationCommand,
inputAndOutputItem,
lambdaAuthFlags,
userInputProcessor,
Expand All @@ -13,12 +13,12 @@ import { addSchemaPermission } from '../../lib/aws-utils'
import { SCHEMA_AWS_PRINCIPAL, getSchemaAppCreateFromUser } from '../../lib/commands/schema-util'


export default class SchemaAppCreateCommand extends APICommand<typeof SchemaAppCreateCommand.flags> {
export default class SchemaAppCreateCommand extends APIOrganizationCommand<typeof SchemaAppCreateCommand.flags> {
static description = 'create an ST Schema connector' +
this.apiDocsURL('postApps')

static flags = {
...APICommand.flags,
...APIOrganizationCommand.flags,
...inputAndOutputItem.flags,
authorize: Flags.boolean({
description: 'authorize connector\'s Lambda functions to be called by SmartThings',
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/schema/delete.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { SchemaApp } from '@smartthings/core-sdk'

import { APICommand, selectFromList, SelectFromListConfig } from '@smartthings/cli-lib'
import { APIOrganizationCommand, selectFromList, SelectFromListConfig } from '@smartthings/cli-lib'


export default class SchemaAppDeleteCommand extends APICommand<typeof SchemaAppDeleteCommand.flags> {
export default class SchemaAppDeleteCommand extends APIOrganizationCommand<typeof SchemaAppDeleteCommand.flags> {
static description = 'delete an ST Schema connector' +
this.apiDocsURL('deleteAppsByEndpointAppId')

static flags = APICommand.flags
static flags = APIOrganizationCommand.flags

static args = [{
name: 'id',
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/schema/regenerate.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { APICommand, selectFromList, outputItem, SelectFromListConfig } from '@smartthings/cli-lib'
import { APIOrganizationCommand, selectFromList, outputItem, SelectFromListConfig } from '@smartthings/cli-lib'
import { SchemaApp } from '@smartthings/core-sdk'


export default class SchemaAppRegenerateCommand extends APICommand<typeof SchemaAppRegenerateCommand.flags> {
export default class SchemaAppRegenerateCommand extends APIOrganizationCommand<typeof SchemaAppRegenerateCommand.flags> {
static description = 'regenerate the clientId and clientSecret of the ST Schema connector\n' +
'NOTE: The previous values will be invalidated, which may affect existing installations.' +
this.apiDocsURL('generateStOauthCredentials')

static flags = {
...APICommand.flags,
...APIOrganizationCommand.flags,
...outputItem.flags,
}

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/schema/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { Flags, Errors } from '@oclif/core'

import { SchemaApp, SchemaAppRequest } from '@smartthings/core-sdk'

import { APICommand, inputItem, selectFromList, lambdaAuthFlags, SelectFromListConfig, userInputProcessor } from '@smartthings/cli-lib'
import { APIOrganizationCommand, inputItem, selectFromList, lambdaAuthFlags, SelectFromListConfig, userInputProcessor } from '@smartthings/cli-lib'

import { addSchemaPermission } from '../../lib/aws-utils'
import { getSchemaAppUpdateFromUser } from '../../lib/commands/schema-util'


export default class SchemaUpdateCommand extends APICommand<typeof SchemaUpdateCommand.flags> {
export default class SchemaUpdateCommand extends APIOrganizationCommand<typeof SchemaUpdateCommand.flags> {
static description = 'update an ST Schema connector' +
this.apiDocsURL('putAppsByEndpointAppId')

static flags = {
...APICommand.flags,
...APIOrganizationCommand.flags,
...inputItem.flags,
// eslint-disable-next-line @typescript-eslint/naming-convention
'dry-run': Flags.boolean({
Expand Down
2 changes: 1 addition & 1 deletion packages/edge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@log4js-node/log4js-api": "^1.0.2",
"@oclif/core": "^1.16.3",
"@smartthings/cli-lib": "^2.2.1",
"@smartthings/core-sdk": "^8.0.0",
"@smartthings/core-sdk": "^8.0.1",
"axios": "^1.5.0",
"inquirer": "^8.2.4",
"js-yaml": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@log4js-node/log4js-api": "^1.0.2",
"@oclif/core": "^1.16.3",
"@smartthings/core-sdk": "^8.0.0",
"@smartthings/core-sdk": "^8.0.1",
"@types/eventsource": "^1.1.9",
"axios": "^1.5.0",
"chalk": "^4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/testlib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@smartthings/cli-lib": "^2.1.1",
"@smartthings/core-sdk": "^8.0.0"
"@smartthings/core-sdk": "^8.0.1"
},
"devDependencies": {
"@types/jest": "^28.1.5",
Expand Down