Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/bright-kings-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smartthings/cli": patch
---

bump log4js to resolve vulnerability
7 changes: 7 additions & 0 deletions .changeset/stale-boxes-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@smartthings/cli-lib": patch
---

- use unknown in sse-io interfaces instead of any
- document sse-io utilities
- bump deps
2,760 changes: 1,608 additions & 1,152 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"devDependencies": {
"@changesets/changelog-github": "^0.4.5",
"@changesets/cli": "^2.23.0",
"@changesets/cli": "^2.23.2",
"@changesets/release-utils": "^0.1.8",
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
Expand Down
30 changes: 15 additions & 15 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,38 @@
]
},
"dependencies": {
"@oclif/core": "^1.9.0",
"@oclif/core": "^1.9.9",
"@oclif/plugin-autocomplete": "^1.3.0",
"@oclif/plugin-not-found": "^2.3.1",
"@oclif/plugin-plugins": "^2.1.0",
"@smartthings/cli-lib": "^1.0.0-beta.10",
"@smartthings/core-sdk": "^5.0.0",
"@smartthings/plugin-cli-edge": "^1.14.1",
"aws-sdk": "^2.1144.0",
"aws-sdk": "^2.1175.0",
"inquirer": "^8.2.4",
"js-yaml": "^4.1.0",
"log4js": "6.3.0"
"log4js": "^6.6.0"
},
"devDependencies": {
"@smartthings/cli-testlib": "^1.0.0-beta.6",
"@types/inquirer": "^8.2.1",
"@types/jest": "^28.1.3",
"@types/jest": "^28.1.5",
"@types/js-yaml": "^4.0.5",
"@types/node": "^16.11.41",
"@typescript-eslint/eslint-plugin": "^5.28.0",
"@typescript-eslint/parser": "^5.28.0",
"eslint": "^8.17.0",
"@types/node": "^16.11.44",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"eslint": "^8.19.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.5.3",
"jest": "^28.1.1",
"eslint-plugin-jest": "^26.6.0",
"jest": "^28.1.3",
"jest-extended": "^0.11.5",
"oclif": "^3.0.1",
"pkg": "^5.7.0",
"oclif": "^3.1.0",
"pkg": "^5.8.0",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.5",
"ts-node": "^10.8.1",
"typescript": "^4.5.4"
"ts-jest": "^28.0.6",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
},
"scripts": {
"lint": "eslint --ext ts src",
Expand Down
32 changes: 16 additions & 16 deletions packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
},
"dependencies": {
"@log4js-node/log4js-api": "^1.0.2",
"@oclif/core": "^1.9.0",
"@oclif/core": "^1.9.9",
"@smartthings/core-sdk": "^5.0.0",
"@types/eventsource": "^1.1.8",
"@types/eventsource": "^1.1.9",
"axios": "^0.21.4",
"chalk": "^4.1.2",
"eventsource": "^2.0.2",
Expand All @@ -42,33 +42,33 @@
"lodash.at": "^4.6.0",
"open": "^8.4.0",
"os-locale": "^5.0.0",
"qs": "^6.10.3",
"qs": "^6.11.0",
"table": "^6.8.0"
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/inquirer": "^8.2.1",
"@types/jest": "^28.1.3",
"@types/jest": "^28.1.5",
"@types/js-yaml": "^4.0.5",
"@types/lodash.at": "^4.6.7",
"@types/node": "^16.11.41",
"@types/node": "^16.11.44",
"@types/qs": "^6.9.7",
"@typescript-eslint/eslint-plugin": "^5.28.0",
"@typescript-eslint/parser": "^5.28.0",
"eslint": "^8.17.0",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"eslint": "^8.19.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.5.3",
"jest": "^28.1.1",
"jest-environment-jsdom": "^28.1.1",
"eslint-plugin-jest": "^26.6.0",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"jest-extended": "^0.11.5",
"log4js": "6.3.0",
"log4js": "^6.6.0",
"mock-stdin": "^1.0.0",
"oclif": "^3.0.1",
"oclif": "^3.1.0",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.5",
"ts-node": "^10.8.1",
"typescript": "^4.5.4"
"ts-jest": "^28.0.6",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
},
"scripts": {
"lint": "eslint --ext ts src",
Expand Down
40 changes: 33 additions & 7 deletions packages/lib/src/sse-io.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,60 @@
import { CliUx } from '@oclif/core'


const formatTimePrefix = '%s '
/**
* This controls how every Server-sent event is formatted to the console in the CLI.
*/
const FORMAT_TIME_PREFIX = '%s '

export interface EventFormat {
/**
* A printf-like format string which can contain zero or more format specifiers.
*/
formatString: string

/**
* Arguments that replace the corresponding specifiers in the formatString.
*/
formatArgs?: string[]

/**
* The time the event was created.
*/
time: string
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type EventFormatter = (event: any) => EventFormat
/**
* A format function used to normalize the raw event data so that the CLI can log consistently.
* Implementations are expected to return printf-like strings and args as well as event time.
*
* @param eventData Any instance of {@link MessageEvent.data}
*/
export type EventFormatter = (eventData: unknown) => EventFormat

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function parseEvent(event: MessageEvent): any {
function parseEvent(event: MessageEvent): unknown {
try {
return JSON.parse(event.data)
} catch (error) {
CliUx.ux.warn(`Unable to parse received event. ${error.message ?? error}`)
}
}

/**
* Log received Server-sent event data to the console.
*
* Aside from the event time which is logged first for all messages, format is specified by the
* caller with a function that returns printf-like strings and args via {@link EventFormat}.
*
* @param event a message received by a target object
* @param formatter a format function that controls how data is displayed
*/
export function logEvent(event: MessageEvent, formatter: EventFormatter): void {
const sse = parseEvent(event)
if (sse === undefined) {
return
}

const eventFormat = formatter(sse)
const outputString = formatTimePrefix.concat(eventFormat.formatString)
const outputString = FORMAT_TIME_PREFIX.concat(eventFormat.formatString)
const outputArgs = eventFormat.formatArgs ? [eventFormat.time].concat(eventFormat.formatArgs) : [eventFormat.time]

CliUx.ux.log(outputString, ...outputArgs)
Expand Down
20 changes: 10 additions & 10 deletions packages/testlib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@
"@smartthings/core-sdk": "^5.0.0"
},
"devDependencies": {
"@types/jest": "^28.1.3",
"@types/jest": "^28.1.5",
"@types/js-yaml": "^4.0.5",
"@types/node": "^16.11.41",
"@typescript-eslint/eslint-plugin": "^5.28.0",
"@typescript-eslint/parser": "^5.28.0",
"eslint": "^8.17.0",
"@types/node": "^16.11.44",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"eslint": "^8.19.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.5.3",
"jest": "^28.1.1",
"eslint-plugin-jest": "^26.6.0",
"jest": "^28.1.3",
"jest-extended": "^0.11.5",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.5",
"ts-node": "^10.8.1",
"typescript": "^4.5.4"
"ts-jest": "^28.0.6",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
},
"scripts": {
"lint": "eslint --ext ts src",
Expand Down