@pipedream/jira_service_desk 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ import jiraServiceDesk from "../../jira_service_desk.app.mjs";
2
+
3
+ export default {
4
+ key: "jira_service_desk-create-comment-on-request",
5
+ name: "Create Comment on Request",
6
+ description: "Create a comment on a customer request. [See the documentation](https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-request/#api-rest-servicedeskapi-request-issueidorkey-comment-post)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ jiraServiceDesk,
11
+ cloudId: {
12
+ propDefinition: [
13
+ jiraServiceDesk,
14
+ "cloudId",
15
+ ],
16
+ },
17
+ requestId: {
18
+ propDefinition: [
19
+ jiraServiceDesk,
20
+ "requestId",
21
+ ({ cloudId }) => ({
22
+ cloudId,
23
+ }),
24
+ ],
25
+ },
26
+ body: {
27
+ type: "string",
28
+ label: "Comment Body",
29
+ description: "The content of the comment",
30
+ },
31
+ isPublic: {
32
+ type: "boolean",
33
+ label: "Public",
34
+ description: "Whether the comment is public or not",
35
+ },
36
+ },
37
+ async run({ $ }) {
38
+ const {
39
+ cloudId, requestId, body, isPublic,
40
+ } = this;
41
+ const response = await this.jiraServiceDesk.createRequestComment({
42
+ $,
43
+ cloudId,
44
+ requestId,
45
+ data: {
46
+ body,
47
+ public: isPublic,
48
+ },
49
+ });
50
+ $.export("$summary", "Successfully created comment on request");
51
+ return response;
52
+ },
53
+ };
@@ -0,0 +1,115 @@
1
+ import jiraServiceDesk from "../../jira_service_desk.app.mjs";
2
+
3
+ export default {
4
+ key: "jira_service_desk-create-request",
5
+ name: "Create Request",
6
+ description:
7
+ "Creates a new customer request. [See the documentation](https://docs.atlassian.com/jira-servicedesk/REST/3.6.2/#servicedeskapi/request-createCustomerRequest)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ jiraServiceDesk,
12
+ cloudId: {
13
+ propDefinition: [
14
+ jiraServiceDesk,
15
+ "cloudId",
16
+ ],
17
+ },
18
+ serviceDeskId: {
19
+ propDefinition: [
20
+ jiraServiceDesk,
21
+ "serviceDeskId",
22
+ ({ cloudId }) => ({
23
+ cloudId,
24
+ }),
25
+ ],
26
+ },
27
+ requestTypeId: {
28
+ propDefinition: [
29
+ jiraServiceDesk,
30
+ "requestTypeId",
31
+ ({
32
+ cloudId, serviceDeskId,
33
+ }) => ({
34
+ cloudId,
35
+ serviceDeskId,
36
+ }),
37
+ ],
38
+ reloadProps: true,
39
+ },
40
+ requestParticipants: {
41
+ type: "string[]",
42
+ label: "Request Participants",
43
+ description:
44
+ "Not available to users who only have the Service Desk customer permission.",
45
+ optional: true,
46
+ },
47
+ },
48
+ async additionalProps() {
49
+ const {
50
+ cloudId, serviceDeskId, requestTypeId,
51
+ } = this;
52
+ const types = await this.jiraServiceDesk.getRequestTypeFields({
53
+ cloudId,
54
+ serviceDeskId,
55
+ requestTypeId,
56
+ });
57
+
58
+ return Object.fromEntries(
59
+ types.map((field) => [
60
+ field.fieldId,
61
+ {
62
+ type: "string",
63
+ label: `Field: "${field.name}"`,
64
+ description: `[See the documentation](https://docs.atlassian.com/jira-servicedesk/REST/3.6.2/#fieldformats) for info on specific fields. If the provided value is not a string, it will be parsed as JSON.${field.description
65
+ ? `
66
+ \\
67
+ Field description: "${field.description}"`
68
+ : ""}${field.jiraSchema
69
+ ? `
70
+ \\
71
+ Field schema: \`${JSON.stringify(field.jiraSchema)}\``
72
+ : ""}`,
73
+ optional: !field.required,
74
+ },
75
+ ]),
76
+ );
77
+ },
78
+ async run({ $ }) {
79
+ const {
80
+ // eslint-disable-next-line no-unused-vars
81
+ jiraServiceDesk,
82
+ cloudId,
83
+ serviceDeskId,
84
+ requestTypeId,
85
+ requestParticipants,
86
+ ...requestFieldValues
87
+ } = this;
88
+
89
+ Object.entries(requestFieldValues).forEach(([
90
+ key,
91
+ value,
92
+ ]) => {
93
+ try {
94
+ const parsedValue = JSON.parse(value);
95
+ requestFieldValues[key] = parsedValue;
96
+ }
97
+ catch (err) {
98
+ // ignore non-serializable values
99
+ }
100
+ });
101
+
102
+ const response = await this.jiraServiceDesk.createCustomerRequest({
103
+ $,
104
+ cloudId,
105
+ data: {
106
+ serviceDeskId,
107
+ requestTypeId,
108
+ requestFieldValues,
109
+ requestParticipants,
110
+ },
111
+ });
112
+ $.export("$summary", "Successfully created request");
113
+ return response;
114
+ },
115
+ };
@@ -0,0 +1,144 @@
1
+ import { axios } from "@pipedream/platform";
2
+
3
+ export default {
4
+ type: "app",
5
+ app: "jira_service_desk",
6
+ propDefinitions: {
7
+ cloudId: {
8
+ type: "string",
9
+ label: "Cloud ID",
10
+ description: "Select a site, or provide a custom ID.",
11
+ async options() {
12
+ const sites = await this.getSites();
13
+ return sites?.filter?.(({ scopes }) => scopes?.includes("write:servicedesk-request")).map(({
14
+ id, name,
15
+ }) => ({
16
+ label: name,
17
+ value: id,
18
+ }));
19
+ },
20
+ },
21
+ serviceDeskId: {
22
+ type: "string",
23
+ label: "Service Desk ID",
24
+ description: "Select a service desk, or provide a custom ID.",
25
+ async options({ cloudId }) {
26
+ const desks = await this.getServiceDesks({
27
+ cloudId,
28
+ });
29
+ return desks?.map?.(({
30
+ id, projectName,
31
+ }) => ({
32
+ label: projectName,
33
+ value: id,
34
+ }));
35
+ },
36
+ },
37
+ requestId: {
38
+ type: "string",
39
+ label: "Request ID",
40
+ description: "Select a request, or provide a custom ID.",
41
+ async options({ cloudId }) {
42
+ const requests = await this.getCustomerRequests({
43
+ cloudId,
44
+ });
45
+ return requests?.map?.(({
46
+ issueId, issueKey, requestFieldValues,
47
+ }) => {
48
+ const summary = requestFieldValues?.find?.(({ fieldId }) => fieldId === "summary")?.value;
49
+ return ({
50
+ label: `(${issueKey}) ${summary}`,
51
+ value: issueId,
52
+ });
53
+ });
54
+ },
55
+ },
56
+ requestTypeId: {
57
+ type: "string",
58
+ label: "Request Type ID",
59
+ description: "Select a request type, or provide a custom ID.",
60
+ async options({
61
+ cloudId, serviceDeskId,
62
+ }) {
63
+ const types = await this.getRequestTypes({
64
+ cloudId,
65
+ serviceDeskId,
66
+ });
67
+ return types?.map?.(({
68
+ id, name,
69
+ }) => ({
70
+ label: name,
71
+ value: id,
72
+ }));
73
+ },
74
+ },
75
+ },
76
+ methods: {
77
+ _baseUrl() {
78
+ return "https://api.atlassian.com";
79
+ },
80
+ async _makeRequest({
81
+ $ = this, path, headers, ...otherOpts
82
+ } = {}) {
83
+ return axios($, {
84
+ ...otherOpts,
85
+ url: this._baseUrl() + path,
86
+ headers: {
87
+ ...headers,
88
+ Authorization: `Bearer ${this.$auth.oauth_access_token}`,
89
+ },
90
+ });
91
+ },
92
+ async getSites() {
93
+ return this._makeRequest({
94
+ path: "/oauth/token/accessible-resources",
95
+ });
96
+ },
97
+ async getServiceDesks({ cloudId }) {
98
+ const response = await this._makeRequest({
99
+ path: `/ex/jira/${cloudId}/rest/servicedeskapi/servicedesk`,
100
+ });
101
+ return response.values;
102
+ },
103
+ async getRequestTypes({
104
+ cloudId, serviceDeskId,
105
+ }) {
106
+ const response = await this._makeRequest({
107
+ path: `/ex/jira/${cloudId}/rest/servicedeskapi/servicedesk/${serviceDeskId}/requesttype`,
108
+ });
109
+ return response.values;
110
+ },
111
+ async getRequestTypeFields({
112
+ cloudId, serviceDeskId, requestTypeId,
113
+ }) {
114
+ const response = await this._makeRequest({
115
+ path: `/ex/jira/${cloudId}/rest/servicedeskapi/servicedesk/${serviceDeskId}/requesttype/${requestTypeId}/field`,
116
+ });
117
+ return response.requestTypeFields;
118
+ },
119
+ async getCustomerRequests({ cloudId }) {
120
+ const response = await this._makeRequest({
121
+ path: `/ex/jira/${cloudId}/rest/servicedeskapi/request`,
122
+ });
123
+ return response.values;
124
+ },
125
+ async createCustomerRequest({
126
+ cloudId, ...opts
127
+ }) {
128
+ return this._makeRequest({
129
+ ...opts,
130
+ method: "POST",
131
+ path: `/ex/jira/${cloudId}/rest/servicedeskapi/request`,
132
+ });
133
+ },
134
+ async createRequestComment({
135
+ cloudId, requestId, ...opts
136
+ }) {
137
+ return this._makeRequest({
138
+ ...opts,
139
+ method: "POST",
140
+ path: `/ex/jira/${cloudId}/rest/servicedeskapi/request/${requestId}/comment`,
141
+ });
142
+ },
143
+ },
144
+ };
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@pipedream/jira_service_desk",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream Jira Service Desk Components",
5
- "main": "dist/app/jira_service_desk.app.mjs",
5
+ "main": "jira_service_desk.app.mjs",
6
6
  "keywords": [
7
7
  "pipedream",
8
8
  "jira_service_desk"
9
9
  ],
10
- "files": [
11
- "dist"
12
- ],
13
10
  "homepage": "https://pipedream.com/apps/jira_service_desk",
14
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
15
12
  "publishConfig": {
16
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^1.5.1"
17
17
  }
18
18
  }
@@ -0,0 +1,61 @@
1
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2
+ import jiraServiceDesk from "../jira_service_desk.app.mjs";
3
+
4
+ export default {
5
+ props: {
6
+ jiraServiceDesk,
7
+ cloudId: {
8
+ propDefinition: [
9
+ jiraServiceDesk,
10
+ "cloudId",
11
+ ],
12
+ },
13
+ db: "$.service.db",
14
+ timer: {
15
+ type: "$.interface.timer",
16
+ default: {
17
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
18
+ },
19
+ },
20
+ },
21
+ methods: {
22
+ _getLastDate() {
23
+ return this.db.get("lastDate") ?? Date.now();
24
+ },
25
+ _setLastDate(value) {
26
+ this.db.set("lastDate", value);
27
+ },
28
+ getSummary() {
29
+ throw new Error("Summary method not implemented in component");
30
+ },
31
+ getRequestDate() {
32
+ throw new Error("Date method not implemented in component");
33
+ },
34
+ },
35
+ async run() {
36
+ const newDate = Date.now();
37
+ const lastDate = this._getLastDate();
38
+
39
+ const { cloudId } = this;
40
+ const requests = await this.jiraServiceDesk.getCustomerRequests({
41
+ cloudId,
42
+ });
43
+
44
+ requests
45
+ ?.filter?.((req) => this.getRequestDate(req) > lastDate)
46
+ .forEach((req) => {
47
+ const ts = this.getRequestDate(req);
48
+ const id = req.issueId + ts.toString();
49
+ const summary =
50
+ req.requestFieldValues.find(({ fieldId }) => fieldId === "summary")
51
+ ?.value ?? req.issueKey;
52
+ this.$emit(req, {
53
+ id,
54
+ summary: `${this.getSummary()}: ${summary}`,
55
+ ts,
56
+ });
57
+ });
58
+
59
+ this._setLastDate(newDate);
60
+ },
61
+ };
@@ -0,0 +1,21 @@
1
+ import common from "../common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "jira_service_desk-new-request-created",
6
+ name: "New Request Created",
7
+ description:
8
+ "Emit new event when a customer request is created. [See the documentation](https://developer.atlassian.com/cloud/jira/service-desk/rest/#api-rest-servicedeskapi-request-get)",
9
+ version: "0.0.1",
10
+ type: "source",
11
+ dedupe: "unique",
12
+ methods: {
13
+ ...common.methods,
14
+ getRequestDate(req) {
15
+ return req.createdDate.epochMillis;
16
+ },
17
+ getSummary() {
18
+ return "New Request";
19
+ },
20
+ },
21
+ };
@@ -0,0 +1,61 @@
1
+ export default {
2
+ _expands: ["participant", "status", "sla", "requestType", "serviceDesk"],
3
+ issueId: "107001",
4
+ issueKey: "HELPDESK-1",
5
+ requestTypeId: "25",
6
+ serviceDeskId: "10",
7
+ createdDate: {
8
+ iso8601: "2015-10-08T14:42:00+0700",
9
+ jira: "2015-10-08T14:42:00.000+0700",
10
+ friendly: "Monday 14:42 PM",
11
+ epochMillis: 1444290120000,
12
+ },
13
+ reporter: {
14
+ name: "fred",
15
+ key: "fred",
16
+ emailAddress: "fred@example.com",
17
+ displayName: "Fred F. User",
18
+ active: true,
19
+ timeZone: "Australia/Sydney",
20
+ _links: {
21
+ jiraRest: "http://www.example.com/jira/rest/api/2/user?username=fred",
22
+ avatarUrls: {
23
+ "48x48":
24
+ "http://www.example.com/jira/secure/useravatar?size=large&ownerId=fred",
25
+ "24x24":
26
+ "http://www.example.com/jira/secure/useravatar?size=small&ownerId=fred",
27
+ "16x16":
28
+ "http://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred",
29
+ "32x32":
30
+ "http://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred",
31
+ },
32
+ self: "http://www.example.com/jira/rest/api/2/user?username=fred",
33
+ },
34
+ },
35
+ requestFieldValues: [
36
+ {
37
+ fieldId: "summary",
38
+ label: "What do you need?",
39
+ value: "Request JSD help via REST",
40
+ },
41
+ {
42
+ fieldId: "description",
43
+ label: "Why do you need this?",
44
+ value: "I need a new mouse for my Mac",
45
+ },
46
+ ],
47
+ currentStatus: {
48
+ status: "Waiting for Support",
49
+ statusDate: {
50
+ iso8601: "2015-10-08T14:01:00+0700",
51
+ jira: "2015-10-08T14:01:00.000+0700",
52
+ friendly: "Today 14:01 PM",
53
+ epochMillis: 1444287660000,
54
+ },
55
+ },
56
+ _links: {
57
+ jiraRest: "http://host:port/context/rest/api/2/issue/107001",
58
+ web: "http://host:port/context/servicedesk/customer/portal/10/HELPDESK-1",
59
+ self: "http://host:port/context/rest/servicedeskapi/request/107001",
60
+ },
61
+ };
@@ -0,0 +1,21 @@
1
+ import common from "../common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "jira_service_desk-request-status-updated",
6
+ name: "Request Status Updated",
7
+ description:
8
+ "Emit new event when a customer request is updated. [See the documentation](https://developer.atlassian.com/cloud/jira/service-desk/rest/#api-rest-servicedeskapi-request-get)",
9
+ version: "0.0.1",
10
+ type: "source",
11
+ dedupe: "unique",
12
+ methods: {
13
+ ...common.methods,
14
+ getRequestDate(req) {
15
+ return req.currentStatus.statusDate.epochMillis;
16
+ },
17
+ getSummary() {
18
+ return "Request Updated";
19
+ },
20
+ },
21
+ };
@@ -0,0 +1,61 @@
1
+ export default {
2
+ _expands: ["participant", "status", "sla", "requestType", "serviceDesk"],
3
+ issueId: "107001",
4
+ issueKey: "HELPDESK-1",
5
+ requestTypeId: "25",
6
+ serviceDeskId: "10",
7
+ createdDate: {
8
+ iso8601: "2015-10-08T14:42:00+0700",
9
+ jira: "2015-10-08T14:42:00.000+0700",
10
+ friendly: "Monday 14:42 PM",
11
+ epochMillis: 1444290120000,
12
+ },
13
+ reporter: {
14
+ name: "fred",
15
+ key: "fred",
16
+ emailAddress: "fred@example.com",
17
+ displayName: "Fred F. User",
18
+ active: true,
19
+ timeZone: "Australia/Sydney",
20
+ _links: {
21
+ jiraRest: "http://www.example.com/jira/rest/api/2/user?username=fred",
22
+ avatarUrls: {
23
+ "48x48":
24
+ "http://www.example.com/jira/secure/useravatar?size=large&ownerId=fred",
25
+ "24x24":
26
+ "http://www.example.com/jira/secure/useravatar?size=small&ownerId=fred",
27
+ "16x16":
28
+ "http://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred",
29
+ "32x32":
30
+ "http://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred",
31
+ },
32
+ self: "http://www.example.com/jira/rest/api/2/user?username=fred",
33
+ },
34
+ },
35
+ requestFieldValues: [
36
+ {
37
+ fieldId: "summary",
38
+ label: "What do you need?",
39
+ value: "Request JSD help via REST",
40
+ },
41
+ {
42
+ fieldId: "description",
43
+ label: "Why do you need this?",
44
+ value: "I need a new mouse for my Mac",
45
+ },
46
+ ],
47
+ currentStatus: {
48
+ status: "Waiting for Support",
49
+ statusDate: {
50
+ iso8601: "2015-10-08T14:01:00+0700",
51
+ jira: "2015-10-08T14:01:00.000+0700",
52
+ friendly: "Today 14:01 PM",
53
+ epochMillis: 1444287660000,
54
+ },
55
+ },
56
+ _links: {
57
+ jiraRest: "http://host:port/context/rest/api/2/issue/107001",
58
+ web: "http://host:port/context/servicedesk/customer/portal/10/HELPDESK-1",
59
+ self: "http://host:port/context/rest/servicedeskapi/request/107001",
60
+ },
61
+ };