Skip to content

Commit 8d5c099

Browse files
committed
Adding optional JSON parsing
1 parent 024ff89 commit 8d5c099

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

components/ringcentral/actions/create-contact/create-contact.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ringcentral from "../../ringcentral.app.mjs";
2+
import utils from "../../common/utils.mjs";
23

34
export default {
45
key: "ringcentral-create-contact",
@@ -48,7 +49,7 @@ export default {
4849
additionalOptions: {
4950
type: "object",
5051
label: "Additional Options",
51-
description: "Additional parameters to set for the contact. [See the documentation](https://developers.ringcentral.com/api-reference/External-Contacts/createContact) for all available parameters. Example: `{ \"notes\": \"Notes for the contact\" }`",
52+
description: "Additional parameters to set for the contact. [See the documentation](https://developers.ringcentral.com/api-reference/External-Contacts/createContact) for all available parameters. Values will be parsed as JSON where applicable. Example: `{ \"notes\": \"Notes for the contact\" }`",
5253
optional: true,
5354
},
5455
},
@@ -75,7 +76,7 @@ export default {
7576
extensionId,
7677
data: {
7778
...data,
78-
...additionalOptions,
79+
...(additionalOptions && utils.parseObjectEntries(additionalOptions)),
7980
},
8081
});
8182

components/ringcentral/common/utils.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,32 @@ function parse(value) {
4747
}
4848
}
4949

50+
function optionalParseAsJSON(value) {
51+
try {
52+
return JSON.parse(value);
53+
} catch (e) {
54+
return value;
55+
}
56+
}
57+
58+
function parseObjectEntries(value) {
59+
const obj = typeof value === "string"
60+
? JSON.parse(value)
61+
: value;
62+
return Object.fromEntries(
63+
Object.entries(obj).map(([
64+
key,
65+
value,
66+
]) => [
67+
key,
68+
optionalParseAsJSON(value),
69+
]),
70+
);
71+
}
72+
5073
export default {
5174
emptyStrToUndefined,
5275
parse,
5376
emptyObjectToUndefined,
77+
parseObjectEntries,
5478
};

0 commit comments

Comments
 (0)