From a9580b8739235c4d928a7d7d105c499452b55800 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Mon, 23 Sep 2024 17:23:34 -0300 Subject: [PATCH 1/4] highergov init --- components/highergov/highergov.app.mjs | 60 +++++++++++++- components/highergov/package.json | 2 +- .../new-pursuit-added-instant.mjs | 82 +++++++++++++++++++ 3 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs diff --git a/components/highergov/highergov.app.mjs b/components/highergov/highergov.app.mjs index 48582999a9bfa..7860004d7a000 100644 --- a/components/highergov/highergov.app.mjs +++ b/components/highergov/highergov.app.mjs @@ -1,11 +1,67 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "highergov", propDefinitions: {}, methods: { - // this.$auth contains connected account data authKeys() { console.log(Object.keys(this.$auth)); }, + _baseUrl() { + return "https://www.highergov.com/zapier"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + method = "GET", + path = "/", + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + "Content-Type": "application/json", + "Accept": "application/json", + "X-API-KEY": this.$auth.api_key, + }, + }); + }, + async getAuth(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/auth", + ...opts, + }); + }, + async subscribeWebhook(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/pipeline/subscribe/", + data: { + target_url: opts.targetUrl, + }, + ...opts, + }); + }, + async unsubscribeWebhook(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/pipeline/unsubscribe/", + ...opts, + }); + }, + async performList(opts = {}) { + return this._makeRequest({ + method: "GET", + path: "/perform/", + ...opts, + }); + }, }, -}; \ No newline at end of file + version: "0.0.{{ts}}", +}; diff --git a/components/highergov/package.json b/components/highergov/package.json index fd07c5831ab44..adb536acda12b 100644 --- a/components/highergov/package.json +++ b/components/highergov/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs b/components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs new file mode 100644 index 0000000000000..6402561358c41 --- /dev/null +++ b/components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs @@ -0,0 +1,82 @@ +import highergov from "../../highergov.app.mjs"; +import { axios } from "@pipedream/platform"; +import crypto from "crypto"; + +export default { + key: "highergov-new-pursuit-added-instant", + name: "New Pursuit Added Instant", + description: "Emit new event when a pursuit is added to the pipeline. [See the documentation](https://docs.highergov.com/import-and-export/zapier-integration)", + version: "0.0.{{ts}}", + type: "source", + dedupe: "unique", + props: { + highergov: { + type: "app", + app: "highergov", + }, + http: { + type: "$.interface.http", + customResponse: true, + }, + db: "$.service.db", + }, + methods: { + _getWebhookId() { + return this.db.get("webhookId"); + }, + _setWebhookId(id) { + this.db.set("webhookId", id); + }, + }, + hooks: { + async deploy() { + const events = await this.highergov.performList({ + max: 50, + }); + for (const event of events) { + this.$emit(event, { + id: event.opp_key, + summary: `New pursuit added: ${event.title}`, + ts: Date.parse(event.current_datetime), + }); + } + }, + async activate() { + const hookId = await this.highergov.subscribeWebhook({ + targetUrl: this.http.endpoint, + }); + this._setWebhookId(hookId); + }, + async deactivate() { + const id = this._getWebhookId(); + await this.highergov.unsubscribeWebhook({ + id, + }); + }, + }, + async run(event) { + const signature = event.headers["x-highergov-signature"]; + const computedSignature = crypto.createHmac("sha256", this.highergov.$auth.api_key) + .update(event.rawBody) + .digest("hex"); + + if (signature !== computedSignature) { + this.http.respond({ + status: 401, + body: "Unauthorized", + }); + return; + } + + this.http.respond({ + status: 200, + }); + + const pursuit = event.body; + this.$emit(pursuit, { + id: pursuit.opp_key, + summary: `New pursuit added: ${pursuit.title}`, + ts: Date.parse(pursuit.current_datetime), + }); + }, +}; From eca76986a7e00223268c900e39cefcdedfa807c6 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 24 Sep 2024 11:59:38 -0300 Subject: [PATCH 2/4] [Components] highergov #14050 Sources - New Pusuit Added (Instant) --- components/highergov/highergov.app.mjs | 52 ++++--------- components/highergov/package.json | 5 +- .../new-pursuit-added-instant.mjs | 77 ++++++------------- .../new-pursuit-added-instant/test-event.mjs | 46 +++++++++++ 4 files changed, 85 insertions(+), 95 deletions(-) create mode 100644 components/highergov/sources/new-pursuit-added-instant/test-event.mjs diff --git a/components/highergov/highergov.app.mjs b/components/highergov/highergov.app.mjs index 7860004d7a000..c79c7ff168aa2 100644 --- a/components/highergov/highergov.app.mjs +++ b/components/highergov/highergov.app.mjs @@ -3,65 +3,39 @@ import { axios } from "@pipedream/platform"; export default { type: "app", app: "highergov", - propDefinitions: {}, methods: { - authKeys() { - console.log(Object.keys(this.$auth)); - }, _baseUrl() { return "https://www.highergov.com/zapier"; }, - async _makeRequest(opts = {}) { - const { - $ = this, - method = "GET", - path = "/", - headers, - ...otherOpts - } = opts; + _headers() { + return { + "Content-Type": "application/json", + "Accept": "application/json", + "X-API-KEY": this.$auth.api_key, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { return axios($, { - ...otherOpts, - method, url: this._baseUrl() + path, - headers: { - ...headers, - "Content-Type": "application/json", - "Accept": "application/json", - "X-API-KEY": this.$auth.api_key, - }, - }); - }, - async getAuth(opts = {}) { - return this._makeRequest({ - method: "POST", - path: "/auth", + headers: this._headers(), ...opts, }); }, - async subscribeWebhook(opts = {}) { + subscribeWebhook(opts = {}) { return this._makeRequest({ method: "POST", path: "/pipeline/subscribe/", - data: { - target_url: opts.targetUrl, - }, ...opts, }); }, - async unsubscribeWebhook(opts = {}) { + unsubscribeWebhook(opts = {}) { return this._makeRequest({ method: "POST", path: "/pipeline/unsubscribe/", ...opts, }); }, - async performList(opts = {}) { - return this._makeRequest({ - method: "GET", - path: "/perform/", - ...opts, - }); - }, }, - version: "0.0.{{ts}}", }; diff --git a/components/highergov/package.json b/components/highergov/package.json index adb536acda12b..4ab0fa38e5339 100644 --- a/components/highergov/package.json +++ b/components/highergov/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/highergov", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream HigherGov Components", "main": "highergov.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.1" } } diff --git a/components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs b/components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs index 6402561358c41..7fafd04bf0443 100644 --- a/components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs +++ b/components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs @@ -1,19 +1,15 @@ import highergov from "../../highergov.app.mjs"; -import { axios } from "@pipedream/platform"; -import crypto from "crypto"; +import sampleEmit from "./test-event.mjs"; export default { key: "highergov-new-pursuit-added-instant", - name: "New Pursuit Added Instant", - description: "Emit new event when a pursuit is added to the pipeline. [See the documentation](https://docs.highergov.com/import-and-export/zapier-integration)", - version: "0.0.{{ts}}", + name: "New Pursuit Added (Instant)", + description: "Emit new event when a pursuit is added to the pipeline.", + version: "0.0.1", type: "source", dedupe: "unique", props: { - highergov: { - type: "app", - app: "highergov", - }, + highergov, http: { type: "$.interface.http", customResponse: true, @@ -21,62 +17,33 @@ export default { db: "$.service.db", }, methods: { - _getWebhookId() { - return this.db.get("webhookId"); - }, - _setWebhookId(id) { - this.db.set("webhookId", id); + emitEvent(event) { + this.$emit(event, { + id: event.opp_key, + summary: `New pursuit added: ${event.title}`, + ts: Date.parse(event.current_datetime), + }); }, }, hooks: { - async deploy() { - const events = await this.highergov.performList({ - max: 50, - }); - for (const event of events) { - this.$emit(event, { - id: event.opp_key, - summary: `New pursuit added: ${event.title}`, - ts: Date.parse(event.current_datetime), - }); - } - }, async activate() { const hookId = await this.highergov.subscribeWebhook({ - targetUrl: this.http.endpoint, + data: { + target_url: this.http.endpoint, + }, }); - this._setWebhookId(hookId); + console.log("hookId: ", hookId); }, async deactivate() { - const id = this._getWebhookId(); - await this.highergov.unsubscribeWebhook({ - id, - }); + await this.highergov.unsubscribeWebhook(); }, }, - async run(event) { - const signature = event.headers["x-highergov-signature"]; - const computedSignature = crypto.createHmac("sha256", this.highergov.$auth.api_key) - .update(event.rawBody) - .digest("hex"); - - if (signature !== computedSignature) { - this.http.respond({ - status: 401, - body: "Unauthorized", - }); - return; - } - - this.http.respond({ - status: 200, - }); - - const pursuit = event.body; - this.$emit(pursuit, { - id: pursuit.opp_key, - summary: `New pursuit added: ${pursuit.title}`, - ts: Date.parse(pursuit.current_datetime), + async run({ body }) { + this.$emit(body, { + id: body.opp_key, + summary: `New pursuit added: ${body.title}`, + ts: Date.parse(body.current_datetime), }); }, + sampleEmit, }; diff --git a/components/highergov/sources/new-pursuit-added-instant/test-event.mjs b/components/highergov/sources/new-pursuit-added-instant/test-event.mjs new file mode 100644 index 0000000000000..9ea44899fda07 --- /dev/null +++ b/components/highergov/sources/new-pursuit-added-instant/test-event.mjs @@ -0,0 +1,46 @@ +export default { + "title": "string", + "description_text": "string", + "source_id": "string", + "source_id_version": "string", + "captured_date": "string", + "posted_date": "string", + "due_date": "string", + "agency": { + "agency_key": "string", + "agency_name": "string", + "agency_abbreviation": "string", + "agency_type": "string", + "path": "string" + }, + "naics_code": { + "naics_code": "string" + }, + "psc_code": { + "psc_code": "string" + }, + "primary_contact_email": { + "contact_title": "string", + "contact_name": "string", + "contact_first_name": "string", + "contact_last_name": "string", + "contact_email": "string", + "contact_phone": "string" + }, + "secondary_contact_email": { + "contact_title": "string", + "contact_name": "string", + "contact_first_name": "string", + "contact_last_name": "string", + "contact_email": "string", + "contact_phone": "string" + }, + "set_aside": "string", + "opp_key": "string", + "version_key": "string", + "source_type": "string", + "unweighted_value": "string", + "current_datetime": "string", + "user_email": "string", + "path": "string" +} \ No newline at end of file From 9dab4cff8af0bf653f552e8598db31dcd19dea68 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 24 Sep 2024 12:01:31 -0300 Subject: [PATCH 3/4] pnpm update --- pnpm-lock.yaml | 119 +++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 58 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 256498568ef5f..af787c081519b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4438,7 +4438,10 @@ importers: '@pipedream/platform': 3.0.0 components/highergov: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.1 + dependencies: + '@pipedream/platform': 3.0.3 components/highlevel_oauth: specifiers: @@ -12794,6 +12797,55 @@ packages: - aws-crt dev: false + /@aws-sdk/client-sso-oidc/3.600.0_tdq3komn4zwyd65w7klbptsu34: + resolution: {integrity: sha512-7+I8RWURGfzvChyNQSyj5/tKrqRbzRl7H+BnTOf/4Vsw1nFOi5ROhlhD4X/Y0QCTacxnaoNcIrqnY7uGGvVRzw==} + engines: {node: '>=16.0.0'} + dependencies: + '@aws-crypto/sha256-browser': 5.2.0 + '@aws-crypto/sha256-js': 5.2.0 + '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/core': 3.598.0 + '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 + '@aws-sdk/middleware-host-header': 3.598.0 + '@aws-sdk/middleware-logger': 3.598.0 + '@aws-sdk/middleware-recursion-detection': 3.598.0 + '@aws-sdk/middleware-user-agent': 3.598.0 + '@aws-sdk/region-config-resolver': 3.598.0 + '@aws-sdk/types': 3.598.0 + '@aws-sdk/util-endpoints': 3.598.0 + '@aws-sdk/util-user-agent-browser': 3.598.0 + '@aws-sdk/util-user-agent-node': 3.598.0 + '@smithy/config-resolver': 3.0.3 + '@smithy/core': 2.2.3 + '@smithy/fetch-http-handler': 3.2.1 + '@smithy/hash-node': 3.0.2 + '@smithy/invalid-dependency': 3.0.2 + '@smithy/middleware-content-length': 3.0.2 + '@smithy/middleware-endpoint': 3.0.4 + '@smithy/middleware-retry': 3.0.6 + '@smithy/middleware-serde': 3.0.3 + '@smithy/middleware-stack': 3.0.3 + '@smithy/node-config-provider': 3.1.3 + '@smithy/node-http-handler': 3.1.2 + '@smithy/protocol-http': 4.0.3 + '@smithy/smithy-client': 3.1.6 + '@smithy/types': 3.3.0 + '@smithy/url-parser': 3.0.3 + '@smithy/util-base64': 3.0.0 + '@smithy/util-body-length-browser': 3.0.0 + '@smithy/util-body-length-node': 3.0.0 + '@smithy/util-defaults-mode-browser': 3.0.6 + '@smithy/util-defaults-mode-node': 3.0.6 + '@smithy/util-endpoints': 2.0.3 + '@smithy/util-middleware': 3.0.3 + '@smithy/util-retry': 3.0.2 + '@smithy/util-utf8': 3.0.0 + tslib: 2.6.3 + transitivePeerDependencies: + - '@aws-sdk/client-sts' + - aws-crt + dev: false + /@aws-sdk/client-sso/3.423.0: resolution: {integrity: sha512-znIufHkwhCIePgaYciIs3x/+BpzR57CZzbCKHR9+oOvGyufEPPpUT5bFLvbwTgfiVkTjuk6sG/ES3U5Bc+xtrA==} engines: {node: '>=14.0.0'} @@ -13029,7 +13081,7 @@ packages: dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 + '@aws-sdk/client-sso-oidc': 3.600.0_tdq3komn4zwyd65w7klbptsu34 '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 '@aws-sdk/middleware-host-header': 3.598.0 @@ -13071,55 +13123,6 @@ packages: - aws-crt dev: false - /@aws-sdk/client-sts/3.600.0_dseaa2p5u2yk67qiepewcq3hkq: - resolution: {integrity: sha512-KQG97B7LvTtTiGmjlrG1LRAY8wUvCQzrmZVV5bjrJ/1oXAU7DITYwVbSJeX9NWg6hDuSk0VE3MFwIXS2SvfLIA==} - engines: {node: '>=16.0.0'} - dependencies: - '@aws-crypto/sha256-browser': 5.2.0 - '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 - '@aws-sdk/core': 3.598.0 - '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 - '@aws-sdk/middleware-host-header': 3.598.0 - '@aws-sdk/middleware-logger': 3.598.0 - '@aws-sdk/middleware-recursion-detection': 3.598.0 - '@aws-sdk/middleware-user-agent': 3.598.0 - '@aws-sdk/region-config-resolver': 3.598.0 - '@aws-sdk/types': 3.598.0 - '@aws-sdk/util-endpoints': 3.598.0 - '@aws-sdk/util-user-agent-browser': 3.598.0 - '@aws-sdk/util-user-agent-node': 3.598.0 - '@smithy/config-resolver': 3.0.3 - '@smithy/core': 2.2.3 - '@smithy/fetch-http-handler': 3.2.1 - '@smithy/hash-node': 3.0.2 - '@smithy/invalid-dependency': 3.0.2 - '@smithy/middleware-content-length': 3.0.2 - '@smithy/middleware-endpoint': 3.0.4 - '@smithy/middleware-retry': 3.0.6 - '@smithy/middleware-serde': 3.0.3 - '@smithy/middleware-stack': 3.0.3 - '@smithy/node-config-provider': 3.1.3 - '@smithy/node-http-handler': 3.1.2 - '@smithy/protocol-http': 4.0.3 - '@smithy/smithy-client': 3.1.6 - '@smithy/types': 3.3.0 - '@smithy/url-parser': 3.0.3 - '@smithy/util-base64': 3.0.0 - '@smithy/util-body-length-browser': 3.0.0 - '@smithy/util-body-length-node': 3.0.0 - '@smithy/util-defaults-mode-browser': 3.0.6 - '@smithy/util-defaults-mode-node': 3.0.6 - '@smithy/util-endpoints': 2.0.3 - '@smithy/util-middleware': 3.0.3 - '@smithy/util-retry': 3.0.2 - '@smithy/util-utf8': 3.0.0 - tslib: 2.6.3 - transitivePeerDependencies: - - '@aws-sdk/client-sso-oidc' - - aws-crt - dev: false - /@aws-sdk/core/3.556.0: resolution: {integrity: sha512-vJaSaHw2kPQlo11j/Rzuz0gk1tEaKdz+2ser0f0qZ5vwFlANjt08m/frU17ctnVKC1s58bxpctO/1P894fHLrA==} engines: {node: '>=14.0.0'} @@ -17446,7 +17449,7 @@ packages: '@aws-sdk/client-sns': 3.423.0 '@aws-sdk/client-sqs': 3.423.0 '@aws-sdk/client-ssm': 3.423.0 - '@aws-sdk/client-sts': 3.600.0_dseaa2p5u2yk67qiepewcq3hkq + '@aws-sdk/client-sts': 3.600.0 '@aws-sdk/s3-request-presigner': 3.609.0 '@pipedream/helper_functions': 0.3.12 '@pipedream/platform': 1.6.6 @@ -17624,8 +17627,8 @@ packages: - debug dev: false - /@pipedream/platform/3.0.3: - resolution: {integrity: sha512-7elalas41lnT8i6EAFkqB7fT/+hkLGEQ1njS6A7CVguTrEswaIYk/seKmkfkRY7+O6qncgnXswYIKCBML9Co7w==} + /@pipedream/platform/3.0.2: + resolution: {integrity: sha512-q/BYGJoNXOVaRlNTDWD7Gjgkcu114gbPrxQ5KCOFbuYfqnJu8AeDGMyMvEPaGPbrWUVwgxjvOnxw4EWqce8ZNQ==} dependencies: axios: 1.7.7 fp-ts: 2.16.9 @@ -17635,8 +17638,8 @@ packages: - debug dev: false - /@pipedream/platform/3.0.2: - resolution: {integrity: sha512-q/BYGJoNXOVaRlNTDWD7Gjgkcu114gbPrxQ5KCOFbuYfqnJu8AeDGMyMvEPaGPbrWUVwgxjvOnxw4EWqce8ZNQ==} + /@pipedream/platform/3.0.3: + resolution: {integrity: sha512-7elalas41lnT8i6EAFkqB7fT/+hkLGEQ1njS6A7CVguTrEswaIYk/seKmkfkRY7+O6qncgnXswYIKCBML9Co7w==} dependencies: axios: 1.7.7 fp-ts: 2.16.9 @@ -23298,7 +23301,7 @@ packages: dev: false /concat-map/0.0.1: - resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} /concat-stream/2.0.0: resolution: {integrity: sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==} @@ -35378,7 +35381,7 @@ packages: dev: false /verror/1.10.0: - resolution: {integrity: sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=} + resolution: {integrity: sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==} engines: {'0': node >=0.6.0} dependencies: assert-plus: 1.0.0 From c165a082de58bc541968184e827fe4e3eda2ec28 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 24 Sep 2024 16:33:15 -0300 Subject: [PATCH 4/4] some adjusts --- .../new-pursuit-added-instant.mjs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs b/components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs index 7fafd04bf0443..e4fd077cdfe72 100644 --- a/components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs +++ b/components/highergov/sources/new-pursuit-added-instant/new-pursuit-added-instant.mjs @@ -16,23 +16,13 @@ export default { }, db: "$.service.db", }, - methods: { - emitEvent(event) { - this.$emit(event, { - id: event.opp_key, - summary: `New pursuit added: ${event.title}`, - ts: Date.parse(event.current_datetime), - }); - }, - }, hooks: { async activate() { - const hookId = await this.highergov.subscribeWebhook({ + await this.highergov.subscribeWebhook({ data: { target_url: this.http.endpoint, }, }); - console.log("hookId: ", hookId); }, async deactivate() { await this.highergov.unsubscribeWebhook();