Skip to content

Commit a9580b8

Browse files
committed
highergov init
1 parent 1ee9386 commit a9580b8

File tree

3 files changed

+141
-3
lines changed

3 files changed

+141
-3
lines changed
Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,67 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "highergov",
46
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
78
authKeys() {
89
console.log(Object.keys(this.$auth));
910
},
11+
_baseUrl() {
12+
return "https://www.highergov.com/zapier";
13+
},
14+
async _makeRequest(opts = {}) {
15+
const {
16+
$ = this,
17+
method = "GET",
18+
path = "/",
19+
headers,
20+
...otherOpts
21+
} = opts;
22+
return axios($, {
23+
...otherOpts,
24+
method,
25+
url: this._baseUrl() + path,
26+
headers: {
27+
...headers,
28+
"Content-Type": "application/json",
29+
"Accept": "application/json",
30+
"X-API-KEY": this.$auth.api_key,
31+
},
32+
});
33+
},
34+
async getAuth(opts = {}) {
35+
return this._makeRequest({
36+
method: "POST",
37+
path: "/auth",
38+
...opts,
39+
});
40+
},
41+
async subscribeWebhook(opts = {}) {
42+
return this._makeRequest({
43+
method: "POST",
44+
path: "/pipeline/subscribe/",
45+
data: {
46+
target_url: opts.targetUrl,
47+
},
48+
...opts,
49+
});
50+
},
51+
async unsubscribeWebhook(opts = {}) {
52+
return this._makeRequest({
53+
method: "POST",
54+
path: "/pipeline/unsubscribe/",
55+
...opts,
56+
});
57+
},
58+
async performList(opts = {}) {
59+
return this._makeRequest({
60+
method: "GET",
61+
path: "/perform/",
62+
...opts,
63+
});
64+
},
1065
},
11-
};
66+
version: "0.0.{{ts}}",
67+
};

components/highergov/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import highergov from "../../highergov.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
import crypto from "crypto";
4+
5+
export default {
6+
key: "highergov-new-pursuit-added-instant",
7+
name: "New Pursuit Added Instant",
8+
description: "Emit new event when a pursuit is added to the pipeline. [See the documentation](https://docs.highergov.com/import-and-export/zapier-integration)",
9+
version: "0.0.{{ts}}",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
highergov: {
14+
type: "app",
15+
app: "highergov",
16+
},
17+
http: {
18+
type: "$.interface.http",
19+
customResponse: true,
20+
},
21+
db: "$.service.db",
22+
},
23+
methods: {
24+
_getWebhookId() {
25+
return this.db.get("webhookId");
26+
},
27+
_setWebhookId(id) {
28+
this.db.set("webhookId", id);
29+
},
30+
},
31+
hooks: {
32+
async deploy() {
33+
const events = await this.highergov.performList({
34+
max: 50,
35+
});
36+
for (const event of events) {
37+
this.$emit(event, {
38+
id: event.opp_key,
39+
summary: `New pursuit added: ${event.title}`,
40+
ts: Date.parse(event.current_datetime),
41+
});
42+
}
43+
},
44+
async activate() {
45+
const hookId = await this.highergov.subscribeWebhook({
46+
targetUrl: this.http.endpoint,
47+
});
48+
this._setWebhookId(hookId);
49+
},
50+
async deactivate() {
51+
const id = this._getWebhookId();
52+
await this.highergov.unsubscribeWebhook({
53+
id,
54+
});
55+
},
56+
},
57+
async run(event) {
58+
const signature = event.headers["x-highergov-signature"];
59+
const computedSignature = crypto.createHmac("sha256", this.highergov.$auth.api_key)
60+
.update(event.rawBody)
61+
.digest("hex");
62+
63+
if (signature !== computedSignature) {
64+
this.http.respond({
65+
status: 401,
66+
body: "Unauthorized",
67+
});
68+
return;
69+
}
70+
71+
this.http.respond({
72+
status: 200,
73+
});
74+
75+
const pursuit = event.body;
76+
this.$emit(pursuit, {
77+
id: pursuit.opp_key,
78+
summary: `New pursuit added: ${pursuit.title}`,
79+
ts: Date.parse(pursuit.current_datetime),
80+
});
81+
},
82+
};

0 commit comments

Comments
 (0)