Skip to content

Commit 5a5ca34

Browse files
committed
[Components] ninjaone - WIP
1 parent 1a47e41 commit 5a5ca34

File tree

11 files changed

+580
-8
lines changed

11 files changed

+580
-8
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import app from "../../ninjaone.app.mjs";
2+
3+
export default {
4+
key: "ninjaone-create-ticket",
5+
name: "Create Ticket",
6+
description: "Create a new support ticket in NinjaOne. [See the documentation](https://app.ninjarmm.com/apidocs/?links.active=core#/ticketing/create).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
clientId: {
12+
label: "Client ID",
13+
description: "The identifier of the client. Organization identifier.",
14+
propDefinition: [
15+
app,
16+
"organizationId",
17+
],
18+
},
19+
ticketFormId: {
20+
propDefinition: [
21+
app,
22+
"ticketFormId",
23+
],
24+
},
25+
subject: {
26+
type: "string",
27+
label: "Subject",
28+
description: "The subject of the ticket. Eg. `CPU with problems`.",
29+
},
30+
status: {
31+
propDefinition: [
32+
app,
33+
"ticketStatus",
34+
],
35+
},
36+
type: {
37+
type: "string",
38+
label: "Ticket Type",
39+
description: "The type of the ticket.",
40+
optional: true,
41+
options: [
42+
"PROBLEM",
43+
"QUESTION",
44+
"INCIDENT",
45+
"TASK",
46+
],
47+
},
48+
assignedAppUserId: {
49+
propDefinition: [
50+
app,
51+
"assignedAppUserId",
52+
],
53+
},
54+
description: {
55+
type: "string",
56+
label: "Description",
57+
description: "The description of the support ticket",
58+
optional: false,
59+
},
60+
isDescriptionPublic: {
61+
type: "boolean",
62+
label: "Description Public",
63+
description: "Whether the description of the ticket is public.",
64+
optional: true,
65+
},
66+
parentTicketId: {
67+
type: "string",
68+
label: "Parent Ticket ID",
69+
description: "The identifier of the parent ticket.",
70+
optional: true,
71+
},
72+
priority: {
73+
type: "string",
74+
label: "Ticket Priority",
75+
description: "The priority of the ticket",
76+
optional: true,
77+
options: [
78+
"NONE",
79+
"LOW",
80+
"MEDIUM",
81+
"HIGH",
82+
],
83+
},
84+
},
85+
methods: {
86+
createTicket(args = {}) {
87+
return this.app.post({
88+
path: "/ticketing/ticket",
89+
...args,
90+
});
91+
},
92+
},
93+
async run({ $ }) {
94+
const {
95+
createTicket,
96+
clientId,
97+
ticketFormId,
98+
subject,
99+
status,
100+
type,
101+
assignedAppUserId,
102+
description,
103+
// isDescriptionPublic,
104+
parentTicketId,
105+
priority,
106+
} = this;
107+
108+
const response = await createTicket({
109+
$,
110+
data: {
111+
clientId,
112+
ticketFormId,
113+
subject,
114+
status,
115+
type,
116+
assignedAppUserId,
117+
description,
118+
// isDescriptionPublic,
119+
parentTicketId,
120+
priority,
121+
},
122+
});
123+
124+
$.export("$summary", "Successfully created ticket.");
125+
126+
return response;
127+
},
128+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import app from "../../ninjaone.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "ninjaone-update-device-custom-fields",
6+
name: "Update Device Custom Fields",
7+
description: "Update custom fields for a device in NinjaOne. Requires a device identifier. Optionally update the device name, group, or status. [See the documentation](https://app.ninjarmm.com/apidocs/?links.active=core#/devices/updateNodeAttributeValues).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
deviceId: {
13+
propDefinition: [
14+
app,
15+
"deviceId",
16+
],
17+
},
18+
data: {
19+
type: "object",
20+
label: "Custom Fields",
21+
description: "Additional custom fields to update.",
22+
},
23+
},
24+
methods: {
25+
updateDeviceCustomFields({
26+
deviceId, ...args
27+
} = {}) {
28+
return this.app.patch({
29+
path: `/device/${deviceId}/custom-fields`,
30+
...args,
31+
});
32+
},
33+
},
34+
async run({ $ }) {
35+
const {
36+
updateDeviceCustomFields,
37+
deviceId,
38+
data,
39+
} = this;
40+
41+
const response = await updateDeviceCustomFields({
42+
$,
43+
deviceId,
44+
data: utils.parse(data),
45+
});
46+
47+
$.export("$summary", "Successfully updated device custom fields.");
48+
return response;
49+
},
50+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const BASE_URL = "https://app.ninjarmm.com";
2+
const VERSION_PATH = "/api/v2";
3+
const LAST_CREATED_AT = "lastCreatedAt";
4+
const DEFAULT_LIMIT = 50;
5+
const DEFAULT_MAX = 600;
6+
const WEBHOOK_ID = "webhookId";
7+
8+
export default {
9+
BASE_URL,
10+
VERSION_PATH,
11+
DEFAULT_MAX,
12+
LAST_CREATED_AT,
13+
DEFAULT_LIMIT,
14+
WEBHOOK_ID,
15+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
3+
function emptyStrToUndefined(value) {
4+
const trimmed = typeof(value) === "string" && value.trim();
5+
return trimmed === ""
6+
? undefined
7+
: value;
8+
}
9+
10+
function parse(value) {
11+
const valueToParse = emptyStrToUndefined(value);
12+
if (typeof(valueToParse) === "object" || valueToParse === undefined) {
13+
return valueToParse;
14+
}
15+
try {
16+
return JSON.parse(valueToParse);
17+
} catch (e) {
18+
throw new ConfigurationError("Make sure the custom expression contains a valid object.");
19+
}
20+
}
21+
22+
export default {
23+
parse,
24+
};

0 commit comments

Comments
 (0)