diff --git a/components/alchemy/.gitignore b/components/alchemy/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/alchemy/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/alchemy/alchemy.app.mjs b/components/alchemy/alchemy.app.mjs new file mode 100644 index 0000000000000..584340384182d --- /dev/null +++ b/components/alchemy/alchemy.app.mjs @@ -0,0 +1,58 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + +export default { + type: "app", + app: "alchemy", + propDefinitions: { + network: { + type: "string", + label: "Network", + description: "Network of the webhook", + options: constants.NETWORKS, + }, + query: { + type: "string", + label: "GraphQL Query", + description: "Create a custom GraphQL query or select `Full Block Receipts` to get all log events for every new block", + options: [ + { + label: "Full Block Receipts", + value: constants.FULL_BLOCK_RECEIPTS, + }, + ], + }, + }, + methods: { + _baseUrl() { + return "https://dashboard.alchemy.com/api"; + }, + _makeRequest({ + $ = this, + path, + ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + "X-Alchemy-Token": this.$auth.auth_token, + }, + ...opts, + }); + }, + createWebhook(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/create-webhook", + ...opts, + }); + }, + deleteWebhook(opts = {}) { + return this._makeRequest({ + method: "DELETE", + path: "/delete-webhook", + ...opts, + }); + }, + }, +}; diff --git a/components/alchemy/app/alchemy.app.ts b/components/alchemy/app/alchemy.app.ts deleted file mode 100644 index 5d8ef75487b4a..0000000000000 --- a/components/alchemy/app/alchemy.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "alchemy", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); diff --git a/components/alchemy/common/constants.mjs b/components/alchemy/common/constants.mjs new file mode 100644 index 0000000000000..9d64361282e57 --- /dev/null +++ b/components/alchemy/common/constants.mjs @@ -0,0 +1,82 @@ +const NETWORKS = [ + "ETH_MAINNET", + "ETH_SEPOLIA", + "ETH_HOLESKY", + "ARBMAINNET", + "ARBSEPOLIA", + "ARBNOVA_MAINNET", + "MATICMAINNET", + "MATICMUMBAI", + "OPTMAINNET", + "OPTGOERLI", + "BASE_MAINNET", + "BASE_SEPOLIA", + "ZKSYNC_MAINNET", + "ZKSYNC_SEPOLIA", + "LINEA_MAINNET", + "LINEA_SEPOLIA", + "GNOSIS_MAINNET", + "GNOSIS_CHIADO", + "FANTOM_MAINNET", + "FANTOM_TESTNET", + "METIS_MAINNET", + "BLAST_MAINNET", + "BLAST_SEPOLIA", + "SHAPE_SEPOLIA", + "ZETACHAIN_MAINNET", + "ZETACHAIN_TESTNET", + "WORLDCHAIN_MAINNET", + "WORLDCHAIN_SEPOLIA", + "BNB_MAINNET", + "BNB_TESTNET", + "AVAX_MAINNET", + "AVAX_FUJI", + "SONEIUM_MINATO", + "GEIST_POLTER", +]; + +const FULL_BLOCK_RECEIPTS = ` +{ + block { + hash, + number, + timestamp, + logs(filter: {addresses: [], topics: []}) { + data, + topics, + index, + account { + address + }, + transaction { + hash, + nonce, + index, + from { + address + }, + to { + address + }, + value, + gasPrice, + maxFeePerGas, + maxPriorityFeePerGas, + gas, + status, + gasUsed, + cumulativeGasUsed, + effectiveGasPrice, + createdContract { + address + } + } + } + } +} +`; + +export default { + NETWORKS, + FULL_BLOCK_RECEIPTS, +}; diff --git a/components/alchemy/package.json b/components/alchemy/package.json index d85cd23208478..747a6d1d2aca0 100644 --- a/components/alchemy/package.json +++ b/components/alchemy/package.json @@ -1,18 +1,18 @@ { "name": "@pipedream/alchemy", - "version": "0.0.3", + "version": "0.1.0", "description": "Pipedream Alchemy Components", - "main": "dist/app/alchemy.app.mjs", + "main": "alchemy.app.mjs", "keywords": [ "pipedream", "alchemy" ], - "files": [ - "dist" - ], "homepage": "https://pipedream.com/apps/alchemy", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/components/alchemy/sources/new-graphql-query-instant/new-graphql-query-instant.mjs b/components/alchemy/sources/new-graphql-query-instant/new-graphql-query-instant.mjs new file mode 100644 index 0000000000000..ae34fa5ee29ff --- /dev/null +++ b/components/alchemy/sources/new-graphql-query-instant/new-graphql-query-instant.mjs @@ -0,0 +1,77 @@ +import alchemy from "../../alchemy.app.mjs"; + +export default { + key: "alchemy-new-graphql-query-instant", + name: "New GraphQL Query (Instant)", + description: "Emit new event when a new GraphQL query is uploaded to Alchemy's Custom Webhook service. [See the documentation](https://docs.alchemy.com/reference/create-webhook)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + alchemy, + db: "$.service.db", + http: { + type: "$.interface.http", + customResponse: true, + }, + network: { + propDefinition: [ + alchemy, + "network", + ], + }, + query: { + propDefinition: [ + alchemy, + "query", + ], + }, + }, + hooks: { + async activate() { + const { data: { id } } = await this.alchemy.createWebhook({ + data: { + network: this.network, + webhook_type: "GRAPHQL", + webhook_url: this.http.endpoint, + graphql_query: this.query, + }, + }); + this._setHookId(id); + }, + async deactivate() { + const hookId = this._getHookId(); + if (hookId) { + await this.alchemy.deleteWebhook({ + params: { + webhook_id: hookId, + }, + }); + } + }, + }, + methods: { + _getHookId() { + return this.db.get("hookId"); + }, + _setHookId(hookId) { + this.db.set("hookId", hookId); + }, + generateMeta(body) { + return { + id: body.id, + summary: `New Event ID: ${body.id}`, + ts: Date.parse(body.createdAt), + }; + }, + }, + async run(event) { + this.http.respond({ + status: 200, + }); + + const { body } = event; + const meta = this.generateMeta(body); + this.$emit(body, meta); + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fbdcd0dad215a..2243e027da915 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -471,7 +471,10 @@ importers: '@pipedream/platform': 2.0.0 components/alchemy: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/alerty: specifiers: @@ -13204,6 +13207,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'} @@ -13439,7 +13491,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 @@ -13481,55 +13533,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'} @@ -17822,7 +17825,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