-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[TRIGGER] Use Webhooks for Vercel Sources #16570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,6 @@ export default { | |
| "READY", | ||
| "CANCELED", | ||
| ], | ||
| WEBHOOK_ID: "webhookId", | ||
| WEBHOOK_SECRET: "webhookSecret", | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| export default { | ||
| BUDGET_REACHED: "budget.reached", | ||
| BUDGET_RESET: "budget.reset", | ||
| DOMAIN_CREATED: "domain.created", | ||
| DEPLOYMENT_CREATED: "deployment.created", | ||
| DEPLOYMENT_ERROR: "deployment.error", | ||
| DEPLOYMENT_CANCELED: "deployment.canceled", | ||
| DEPLOYMENT_SUCCEEDED: "deployment.succeeded", | ||
| DEPLOYMENT_READY: "deployment.ready", | ||
| DEPLOYMENT_CHECK_REREQUESTED: "deployment.check-rerequested", | ||
| DEPLOYMENT_PROMOTED: "deployment.promoted", | ||
| DEPLOYMENT_INTEGRATION_ACTION_START: "deployment.integration.action.start", | ||
| DEPLOYMENT_INTEGRATION_ACTION_CANCEL: "deployment.integration.action.cancel", | ||
| DEPLOYMENT_INTEGRATION_ACTION_CLEANUP: "deployment.integration.action.cleanup", | ||
| EDGE_CONFIG_CREATED: "edge-config.created", | ||
| EDGE_CONFIG_DELETED: "edge-config.deleted", | ||
| EDGE_CONFIG_ITEMS_UPDATED: "edge-config.items.updated", | ||
| FIREWALL_ATTACK: "firewall.attack", | ||
| INTEGRATION_CONFIGURATION_PERMISSION_UPGRADED: "integration-configuration.permission-upgraded", | ||
| INTEGRATION_CONFIGURATION_REMOVED: "integration-configuration.removed", | ||
| INTEGRATION_CONFIGURATION_SCOPE_CHANGE_CONFIRMED: "integration-configuration.scope-change-confirmed", | ||
| INTEGRATION_RESOURCE_PROJECT_CONNECTED: "integration-resource.project-connected", | ||
| INTEGRATION_RESOURCE_PROJECT_DISCONNECTED: "integration-resource.project-disconnected", | ||
| PROJECT_CREATED: "project.created", | ||
| PROJECT_REMOVED: "project.removed", | ||
| DEPLOYMENT_CHECKS_COMPLETED: "deployment-checks-completed", | ||
| DEPLOYMENT_READY_: "deployment-ready", | ||
| DEPLOYMENT_PREPARED: "deployment-prepared", | ||
| DEPLOYMENT_ERROR_: "deployment-error", | ||
| DEPLOYMENT_CHECK_REREQUESTED_: "deployment-check-rerequested", | ||
| DEPLOYMENT_CANCELED_: "deployment-canceled", | ||
| PROJECT_CREATED_: "project-created", | ||
| PROJECT_REMOVED_: "project-removed", | ||
| DOMAIN_CREATED_: "domain-created", | ||
| DEPLOYMENT_: "deployment", | ||
| INTEGRATION_CONFIGURATION_PERMISSION_UPDATED: "integration-configuration-permission-updated", | ||
| INTEGRATION_CONFIGURATION_REMOVED_: "integration-configuration-removed", | ||
| INTEGRATION_CONFIGURATION_SCOPE_CHANGE_CONFIRMED_: "integration-configuration-scope-change-confirmed", | ||
| MARKETPLACE_INVOICE_CREATED: "marketplace.invoice.created", | ||
| MARKETPLACE_INVOICE_PAID: "marketplace.invoice.paid", | ||
| MARKETPLACE_INVOICE_NOTPAID: "marketplace.invoice.notpaid", | ||
| MARKETPLACE_INVOICE_REFUNDED: "marketplace.invoice.refunded", | ||
| OBSERVABILITY_ANOMALY: "observability.anomaly", | ||
| TEST_WEBHOOK: "test-webhook", | ||
| }; |
151 changes: 151 additions & 0 deletions
151
components/vercel_token_auth/sources/common/webhook.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import { createHmac } from "crypto"; | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import app from "../../vercel_token_auth.app.mjs"; | ||
| import constants from "../../common/constants.mjs"; | ||
|
|
||
| export default { | ||
| props: { | ||
| app, | ||
| db: "$.service.db", | ||
| http: "$.interface.http", | ||
| teamId: { | ||
| label: "Team ID", | ||
| description: "The Team identifier to perform the request on behalf of. Eg. `team_1a2b3c4d5e6f7g8h9i0j1k2l`", | ||
| optional: true, | ||
| propDefinition: [ | ||
| app, | ||
| "team", | ||
| ], | ||
| }, | ||
| slug: { | ||
| label: "Slug", | ||
| description: "The Team slug to perform the request on behalf of. Eg. `my-team-url-slug`", | ||
| optional: true, | ||
| propDefinition: [ | ||
| app, | ||
| "team", | ||
| () => ({ | ||
| mapper: ({ slug }) => slug, | ||
| }), | ||
| ], | ||
| }, | ||
| projectIds: { | ||
| type: "string[]", | ||
| label: "Project IDs", | ||
| description: "The Project identifiers to perform the request on behalf of", | ||
| optional: true, | ||
| propDefinition: [ | ||
| app, | ||
| "project", | ||
| ], | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async activate() { | ||
| const { | ||
| createWebhook, | ||
| getEvents, | ||
| http: { endpoint: url }, | ||
| setWebhookId, | ||
| setWebhookSecret, | ||
| teamId, | ||
| slug, | ||
| projectIds, | ||
| } = this; | ||
|
|
||
| const response = | ||
| await createWebhook({ | ||
| params: { | ||
| teamId, | ||
| slug, | ||
| }, | ||
| data: { | ||
| url, | ||
| events: getEvents(), | ||
| projectIds, | ||
| }, | ||
| }); | ||
|
|
||
| setWebhookId(response.id); | ||
| setWebhookSecret(response.secret); | ||
| }, | ||
| async deactivate() { | ||
| const { | ||
| deleteWebhook, | ||
| getWebhookId, | ||
| } = this; | ||
|
|
||
| const webhookId = getWebhookId(); | ||
| if (webhookId) { | ||
| await deleteWebhook({ | ||
| webhookId, | ||
| }); | ||
| } | ||
| }, | ||
| }, | ||
| methods: { | ||
| generateMeta() { | ||
| throw new ConfigurationError("generateMeta is not implemented"); | ||
| }, | ||
| setWebhookId(value) { | ||
| this.db.set(constants.WEBHOOK_ID, value); | ||
| }, | ||
| getWebhookId() { | ||
| return this.db.get(constants.WEBHOOK_ID); | ||
| }, | ||
| setWebhookSecret(value) { | ||
| this.db.set(constants.WEBHOOK_SECRET, value); | ||
| }, | ||
| getWebhookSecret() { | ||
| return this.db.get(constants.WEBHOOK_SECRET); | ||
| }, | ||
| getEvents() { | ||
| throw new ConfigurationError("getEvents is not implemented"); | ||
| }, | ||
| isSignatureValid(incommingSignature, bodyRaw) { | ||
| const secret = this.getWebhookSecret(); | ||
| const rawBodyBuffer = Buffer.from(bodyRaw, "utf-8"); | ||
| const expectedSignature = | ||
| createHmac("sha1", secret) | ||
| .update(rawBodyBuffer) | ||
| .digest("hex"); | ||
| return expectedSignature === incommingSignature; | ||
| }, | ||
| processResource(resource) { | ||
| this.$emit(resource, this.generateMeta(resource)); | ||
| }, | ||
| createWebhook(args = {}) { | ||
| return this.app.makeRequest({ | ||
| method: "POST", | ||
| endpoint: "v1/webhooks", | ||
| ...args, | ||
| }); | ||
| }, | ||
| deleteWebhook({ | ||
| webhookId, ...args | ||
| } = {}) { | ||
| return this.app.makeRequest({ | ||
| method: "DELETE", | ||
| endpoint: `v1/webhooks/${webhookId}`, | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ | ||
| body, bodyRaw, headers, | ||
| }) { | ||
| const incommingSignature = headers["x-vercel-signature"]; | ||
|
|
||
| if (!incommingSignature) { | ||
| throw new ConfigurationError("Missing x-vercel-signature header"); | ||
| } | ||
|
|
||
| const isValid = this.isSignatureValid(incommingSignature, bodyRaw); | ||
|
|
||
| if (!isValid) { | ||
| throw new ConfigurationError("Invalid x-vercel-signature header"); | ||
| } | ||
|
|
||
| this.processResource(body); | ||
| }, | ||
| }; | ||
27 changes: 27 additions & 0 deletions
27
...nts/vercel_token_auth/sources/deployment-canceled-instant/deployment-canceled-instant.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import common from "../common/webhook.mjs"; | ||
| import events from "../common/events.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "vercel_token_auth-deployment-canceled-instant", | ||
| name: "Deployment Canceled (Instant)", | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| description: "Emit new event when a deployment is canceled [See the documentation](https://vercel.com/docs/rest-api/reference/endpoints/webhooks/creates-a-webhook).", | ||
| type: "source", | ||
| version: "0.0.1", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getEvents() { | ||
| return [ | ||
| events.DEPLOYMENT_CANCELED, | ||
| ]; | ||
| }, | ||
| generateMeta(resource) { | ||
| return { | ||
| id: resource.id, | ||
| summary: `Deployment Canceled: ${resource.id}`, | ||
| ts: resource.createdAt, | ||
| }; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }; | ||
27 changes: 27 additions & 0 deletions
27
components/vercel_token_auth/sources/deployment-error-instant/deployment-error-instant.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import common from "../common/webhook.mjs"; | ||
| import events from "../common/events.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "vercel_token_auth-deployment-error-instant", | ||
| name: "Deployment Error (Instant)", | ||
| description: "Emit new event when a deployment encounters an error [See the documentation](https://vercel.com/docs/rest-api/reference/endpoints/webhooks/creates-a-webhook).", | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type: "source", | ||
| version: "0.0.1", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getEvents() { | ||
| return [ | ||
| events.DEPLOYMENT_ERROR, | ||
| ]; | ||
| }, | ||
| generateMeta(resource) { | ||
| return { | ||
| id: resource.id, | ||
| summary: `Deployment Error: ${resource.id}`, | ||
| ts: resource.createdAt, | ||
| }; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }; | ||
27 changes: 27 additions & 0 deletions
27
...s/vercel_token_auth/sources/deployment-succeeded-instant/deployment-succeeded-instant.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import common from "../common/webhook.mjs"; | ||
| import events from "../common/events.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "vercel_token_auth-deployment-succeeded-instant", | ||
| name: "Deployment Succeeded (Instant)", | ||
| description: "Emit new event when a deployment successfully completes [See the documentation](https://vercel.com/docs/rest-api/reference/endpoints/webhooks/creates-a-webhook).", | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type: "source", | ||
| version: "0.0.1", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getEvents() { | ||
| return [ | ||
| events.DEPLOYMENT_SUCCEEDED, | ||
| ]; | ||
| }, | ||
| generateMeta(resource) { | ||
| return { | ||
| id: resource.id, | ||
| summary: `Deployment Succeeded: ${resource.id}`, | ||
| ts: resource.createdAt, | ||
| }; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }; | ||
27 changes: 27 additions & 0 deletions
27
components/vercel_token_auth/sources/new-deployment-instant/new-deployment-instant.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import common from "../common/webhook.mjs"; | ||
| import events from "../common/events.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "vercel_token_auth-new-deployment-instant", | ||
| name: "New Deployment (Instant)", | ||
| description: "Emit new event when a deployment is created [See the documentation](https://vercel.com/docs/rest-api/reference/endpoints/webhooks/creates-a-webhook).", | ||
| type: "source", | ||
| version: "0.0.1", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getEvents() { | ||
| return [ | ||
| events.DEPLOYMENT_CREATED, | ||
| ]; | ||
| }, | ||
| generateMeta(resource) { | ||
| return { | ||
| id: resource.id, | ||
| summary: `New Deployment: ${resource.id}`, | ||
| ts: resource.createdAt, | ||
| }; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.