Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "vercel_token_auth-cancel-deployment",
name: "Cancel Deployment",
description: "Cancel a deployment which is currently building. [See the documentation](https://vercel.com/docs/rest-api/endpoints/deployments#cancel-a-deployment)",
version: "0.0.4",
version: "0.0.5",
type: "action",
props: {
vercelTokenAuth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "vercel_token_auth-create-deployment",
name: "Create Deployment",
description: "Create a new deployment from a GitHub repository. [See the documentation](https://vercel.com/docs/rest-api/endpoints/deployments#create-a-new-deployment)",
version: "0.0.4",
version: "0.0.5",
type: "action",
props: {
vercelTokenAuth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "vercel_token_auth-list-deployments",
name: "List Deployments",
description: "List deployments under the account corresponding to the API token. [See the documentation](https://vercel.com/docs/rest-api/endpoints/deployments#list-deployments)",
version: "0.0.4",
version: "0.0.5",
type: "action",
props: {
vercelTokenAuth,
Expand Down
2 changes: 2 additions & 0 deletions components/vercel_token_auth/common/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export default {
"READY",
"CANCELED",
],
WEBHOOK_ID: "webhookId",
WEBHOOK_SECRET: "webhookSecret",
};
5 changes: 3 additions & 2 deletions components/vercel_token_auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/vercel_token_auth",
"version": "0.0.5",
"version": "0.1.0",
"description": "Pipedream Vercel (token-based auth) Components",
"main": "vercel_token_auth.app.mjs",
"keywords": [
Expand All @@ -13,6 +13,7 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
"@pipedream/platform": "^3.0.3",
"crypto": "^1.0.1"
}
}
45 changes: 45 additions & 0 deletions components/vercel_token_auth/sources/common/events.mjs
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 components/vercel_token_auth/sources/common/webhook.mjs
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);
},
};
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)",

Check warning on line 7 in components/vercel_token_auth/sources/deployment-canceled-instant/deployment-canceled-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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,
};
},
},
};
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)",

Check warning on line 7 in components/vercel_token_auth/sources/deployment-error-instant/deployment-error-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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).",
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,
};
},
},
};
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)",

Check warning on line 7 in components/vercel_token_auth/sources/deployment-succeeded-instant/deployment-succeeded-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
description: "Emit new event when a deployment successfully completes [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_SUCCEEDED,
];
},
generateMeta(resource) {
return {
id: resource.id,
summary: `Deployment Succeeded: ${resource.id}`,
ts: resource.createdAt,
};
},
},
};
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,
};
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "vercel_token_auth-new-deployment",
name: "New Deployment",
description: "Emit new event when a deployment is created",
version: "0.0.4",
version: "0.0.5",
type: "source",
dedupe: "unique",
props: {
Expand Down
14 changes: 9 additions & 5 deletions components/vercel_token_auth/vercel_token_auth.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ export default {
type: "string",
label: "Team",
description: "The Team identifier or slug to perform the request on behalf of",
async options() {
async options({
mapper = ({
slug: label, id: value,
}) => ({
label,
value,
}),
}) {
try {
const teams = await this.listTeams();
return teams?.map((team) => ({
label: team.slug,
value: team.id,
})) ?? [];
return teams?.map(mapper) ?? [];
} catch (e) {
throw new Error(e.message);
}
Expand Down
Loading
Loading