Skip to content

Commit 646b5e0

Browse files
authored
Merging pull request #15960
1 parent 98c0eb6 commit 646b5e0

File tree

4 files changed

+187
-11
lines changed

4 files changed

+187
-11
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import app from "../../navigatr.app.mjs";
2+
3+
export default {
4+
key: "navigatr-issue-badge",
5+
name: "Issue Badge",
6+
description: "Issue a badge to a recipient. [See the documentation](https://api.navigatr.app/docs#/Badge/issue_badge_v1_badge__badge_id__issue_put)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
providerId: {
12+
propDefinition: [
13+
app,
14+
"providerId",
15+
],
16+
},
17+
badgeId: {
18+
propDefinition: [
19+
app,
20+
"badgeId",
21+
],
22+
},
23+
recipientHasAccount: {
24+
propDefinition: [
25+
app,
26+
"recipientHasAccount",
27+
],
28+
reloadProps: true,
29+
},
30+
recipientId: {
31+
propDefinition: [
32+
app,
33+
"recipientId",
34+
],
35+
},
36+
recipientEmail: {
37+
propDefinition: [
38+
app,
39+
"recipientEmail",
40+
],
41+
disabled: true,
42+
hidden: true,
43+
},
44+
recipientFirstname: {
45+
propDefinition: [
46+
app,
47+
"recipientFirstname",
48+
],
49+
disabled: true,
50+
hidden: true,
51+
},
52+
recipientLastname: {
53+
propDefinition: [
54+
app,
55+
"recipientLastname",
56+
],
57+
disabled: true,
58+
hidden: true,
59+
},
60+
},
61+
async additionalProps(existingProps) {
62+
const props = {};
63+
if (!this.recipientHasAccount) {
64+
existingProps.recipientId.hidden = true;
65+
existingProps.recipientId.disabled = true;
66+
existingProps.recipientEmail.hidden = false;
67+
existingProps.recipientEmail.disabled = false;
68+
existingProps.recipientFirstname.hidden = false;
69+
existingProps.recipientFirstname.disabled = false;
70+
existingProps.recipientLastname.hidden = false;
71+
existingProps.recipientLastname.disabled = false;
72+
}
73+
return props;
74+
},
75+
async run({ $ }) {
76+
const response = await this.app.issueBadge({
77+
$,
78+
badgeId: this.badgeId,
79+
data: {
80+
provider_id: this.providerId,
81+
recipient_id: this.recipientId,
82+
recipient_email: this.recipientEmail,
83+
recipient_firstname: this.recipientFirstname,
84+
recipient_lastname: this.recipientLastname,
85+
},
86+
});
87+
$.export("$summary", "Successfully issued badge");
88+
return response;
89+
},
90+
};
Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,90 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "navigatr",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
providerId: {
8+
type: "string",
9+
label: "Provider ID",
10+
description: "ID of the badge provider",
11+
async options() {
12+
const response = await this.getUserDetails();
13+
const providerIds = response.providers;
14+
return providerIds.map(({
15+
name, id,
16+
}) => ({
17+
label: name,
18+
value: id,
19+
}));
20+
},
21+
},
22+
recipientHasAccount: {
23+
type: "boolean",
24+
label: "Recipient Has Account",
25+
description: "Does the recipient have an account in the system?",
26+
},
27+
recipientId: {
28+
type: "string",
29+
label: "Recipient ID",
30+
description: "ID of the badge recipient",
31+
},
32+
recipientEmail: {
33+
type: "string",
34+
label: "Recipient Email",
35+
description: "Email of the recipient",
36+
},
37+
recipientFirstname: {
38+
type: "string",
39+
label: "First Name",
40+
description: "First Name of the recipient",
41+
},
42+
recipientLastname: {
43+
type: "string",
44+
label: "Last Name",
45+
description: "Last Name of the recipient",
46+
},
47+
badgeId: {
48+
type: "string",
49+
label: "Badge ID",
50+
description: "ID of the badge to be issued",
51+
},
52+
},
553
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
54+
_baseUrl() {
55+
return "https://api.navigatr.app/v1";
56+
},
57+
async _makeRequest(opts = {}) {
58+
const {
59+
$ = this,
60+
path,
61+
headers,
62+
...otherOpts
63+
} = opts;
64+
return axios($, {
65+
...otherOpts,
66+
url: this._baseUrl() + path,
67+
headers: {
68+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
69+
...headers,
70+
},
71+
});
72+
},
73+
74+
async issueBadge({
75+
badgeId, ...args
76+
}) {
77+
return this._makeRequest({
78+
path: `/badge/${badgeId}/issue`,
79+
method: "put",
80+
...args,
81+
});
82+
},
83+
async getUserDetails(args = {}) {
84+
return this._makeRequest({
85+
path: "/user_detail/0",
86+
...args,
87+
});
988
},
1089
},
11-
};
90+
};

components/navigatr/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/navigatr",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Navigatr Components",
55
"main": "navigatr.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
1518
}

pnpm-lock.yaml

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)