Skip to content

Commit

Permalink
add custom_metadata update on devices and connected_accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Neiva07 committed Jan 23, 2024
1 parent 0d794ee commit a22936a
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 8 deletions.
82 changes: 82 additions & 0 deletions lib/interact-for-custom-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import prompts from "prompts"
import { getSeam } from "./get-seam"
import { CustomMetadata } from "@seamapi/types/connect"
export const interactForCustomMetadata = async (custom_metadata: CustomMetadata) => {
const seam = await getSeam()
const updated_custom_metadata = {...custom_metadata}


const displayCurrentCustomMetadata = () => {
console.log('Current custom metadata.')
if (Object.keys(updated_custom_metadata).length > 0) {
Object.keys(updated_custom_metadata).forEach((key, index) => {
console.log(`${index + 1}: ${key}: ${updated_custom_metadata[key]}`)
})
} else {
console.log("The custom metadata param is empty.")
}
}

let action: string

do {
displayCurrentCustomMetadata()

const response = await prompts({
type: "select",
name: "action",
message: "Choose an action:",
choices: [
{ title: "Add an item to params", value: "add" },
{ title: "Remove an item from params", value: "remove" },
{ title: "Finish editing params", value: "done" },
],
})

action = response.action

if (action === "add") {
const { newKey } = await prompts({
type: "text",
name: "newKey",
message: "Enter a key to add or edit:",
})

let { newValue } = await prompts({
type: "text",
name: "newValue",
message: "Enter the new value to add or edit (or null to delete):",
})
if (newKey) {
if (newValue === "false" || newValue === "true") {
newValue = Boolean(newValue)
}
if (newValue === "null") {
updated_custom_metadata[newKey] = null
} else {
updated_custom_metadata[newKey] = newValue
}

}
} else if (action === "remove") {

const {custom_key_to_remove} = await prompts({
type: "select",
name: "custom_key_to_remove",
message: "Choose a key-value pair to remove from params:",
choices: Object.keys(updated_custom_metadata).map(custom_metadata_key => {
return ({
title: `${custom_metadata_key}: ${updated_custom_metadata[custom_metadata_key]}`,
value: custom_metadata_key
})
}),
})

if (custom_key_to_remove) {
delete custom_metadata[custom_key_to_remove]
}
}
} while (action !== "done")

return updated_custom_metadata
}
8 changes: 7 additions & 1 deletion lib/interact-for-open-api-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ContextHelpers } from "./types"
import { interactForAcsEntrance } from "./interact-for-acs-entrance"
import { ellipsis } from "./util/ellipsis"
import { interactForArray } from "./interact-for-array"
import { interactForCustomMetadata } from "./interact-for-custom-metadata"

const ergonomicPropOrder = [
"name",
Expand Down Expand Up @@ -160,7 +161,12 @@ export const interactForOpenApiObject = async (
) {
args.params[paramToEdit] = await interactForTimestamp()
return interactForOpenApiObject(args, ctx)
}
} else if (
paramToEdit === "custom_metadata"
) {
args.params[paramToEdit] = await interactForCustomMetadata( args.params[paramToEdit] || {})
return interactForOpenApiObject(args, ctx)
}

if ("type" in prop) {
if (prop.type === "string") {
Expand Down
14 changes: 8 additions & 6 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"sourcemap": true
},
"devDependencies": {
"@seamapi/types": "^1.88.0",
"@swc/core": "^1.3.100",
"@types/command-line-usage": "^5.0.4",
"@types/configstore": "^6.0.2",
Expand Down Expand Up @@ -54,7 +55,6 @@
},
"dependencies": {
"@seamapi/http": "^0.12.0",
"@seamapi/types": "^1.75.0",
"open": "^10.0.2",
"swagger-parser": "^10.0.3"
}
Expand Down

0 comments on commit a22936a

Please sign in to comment.