-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add custom_metadata update on devices and connected_accounts
- Loading branch information
Showing
4 changed files
with
98 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters