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
71 changes: 71 additions & 0 deletions components/caspio/actions/create-record/create-record.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import caspio from "../../caspio.app.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
key: "caspio-create-record",
name: "Create Record",
description: "Create a new record in the specified table. [See the documentation](https://demo.caspio.com/integrations/rest/swagger/index.html)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
props: {
caspio,
table: {
propDefinition: [
caspio,
"table",
],
reloadProps: true,
},
},
async additionalProps() {
const props = {};
const { Result: fields } = await this.caspio.listTableFields({
table: this.table,
});
for (const field of fields) {
if (!field.Editable) continue;
props[field.Name] = {
type: field.Type === "YES/NO"
? "boolean"
: "string",
label: field.Name,
optional: true,
};
}
return props;
},
async run({ $ }) {
const {
caspio,
table,
...data
} = this;

if (Object.keys(data).length === 0) {
throw new ConfigurationError("Must provide at least one field");
}

const { Result: fields } = await this.caspio.listTableFields({
table: this.table,
});

for (const field of fields) {
if (field.Type === "NUMBER" && data[field.Name]) {
data[field.Name] = +data[field.Name];
}
}

const response = await caspio.createRecord({
$,
table,
data,
});
$.export("$summary", `Successfully created record in table ${table}`);
return response;
},
};
80 changes: 76 additions & 4 deletions components/caspio/caspio.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,83 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "caspio",
propDefinitions: {},
propDefinitions: {
table: {
type: "string",
label: "Table",
description: "The table to listen for events on",
async options() {
const { Result: tables } = await this.listTables();
return tables?.map((table) => table) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_domain() {
return this.$auth.domain.endsWith("/")
? this.$auth.domain.slice(0, -1)
: this.$auth.domain;
},
_baseUrl() {
return `${this._domain()}/integrations/rest/v3`;
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
},
...opts,
});
},
listTables(opts = {}) {
return this._makeRequest({
path: "/tables",
...opts,
});
},
listTableFields({
table, ...opts
}) {
return this._makeRequest({
path: `/tables/${table}/fields`,
...opts,
});
},
createRecord({
table, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/tables/${table}/records`,
...opts,
});
},
createWebhook(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/outgoingWebhooks",
...opts,
});
},
createWebhookEvent({
webhookId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/outgoingWebhooks/${webhookId}/events`,
...opts,
});
},
deleteWebhook(webhookId) {
return this._makeRequest({
method: "DELETE",
path: `/outgoingWebhooks/${webhookId}`,
});
},
},
};
5 changes: 4 additions & 1 deletion components/caspio/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/caspio",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream Caspio Components",
"main": "caspio.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.1"
}
}
78 changes: 78 additions & 0 deletions components/caspio/sources/common/base-webhook.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import caspio from "../../caspio.app.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
props: {
caspio,
db: "$.service.db",
http: {
type: "$.interface.http",
customResponse: true,
},
name: {
type: "string",
label: "Name",
description: "Meaningful label that identifies the webhook",
},
table: {
propDefinition: [
caspio,
"table",
],
},
},
hooks: {
async activate() {
const { Id: webhookId } = await this.caspio.createWebhook({
data: {
Name: this.name,
OutgoingUrls: [
this.http.endpoint,
],
},
});
this._setWebhookId(webhookId);

await this.caspio.createWebhookEvent({
webhookId,
data: {
EventType: this.getEventType(),
ObjectName: this.table,
},
});
},
async deactivate() {
const webhookId = this._getWebhookId();
if (!webhookId) {
return;
}
await this.caspio.deleteWebhook(webhookId);
},
},
methods: {
_setWebhookId(webhookId) {
this.db.set("webhookId", webhookId);
},
_getWebhookId() {
return this.db.get("webhookId");
},
getEventType() {
throw new ConfigurationError("getEventType is not implemented");
},
generateMeta() {
throw new ConfigurationError("generateMeta is not implemented");
},
},
async run({ body }) {
this.http.respond({
status: 200,
});

if (!body) {
return;
}

const meta = this.generateMeta(body);
this.$emit(body, meta);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import common from "../common/base-webhook.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "caspio-new-record-created",
name: "New Record Created (Instant)",
description: "Emit new event when a new record in specified table is created",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getEventType() {
return "table.recordInsert";
},
generateMeta(body) {
return {
id: body.eventId,
summary: `New record created with PK_ID: ${body.data[0].PK_ID}`,
ts: Date.parse(body.eventDate),
};
},
},
sampleEmit,
};
17 changes: 17 additions & 0 deletions components/caspio/sources/new-record-created/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
"eventId": "p150qb",
"messageId": "bd79b323-ae75-4d7d-884e-4cf2902edb93",
"webhookId": "b5x49p",
"accountId": "",
"secret": "",
"eventDate": "2026-01-16T19:52:55",
"eventType": "table.recordInsert",
"objectName": "New_Table",
"data": [
{
"PK_ID": 1,
"id": "1",
"name": "examplee"
}
]
}
26 changes: 26 additions & 0 deletions components/caspio/sources/record-deleted/record-deleted.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import common from "../common/base-webhook.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "caspio-record-deleted",
name: "Record Deleted (Instant)",

Check warning on line 7 in components/caspio/sources/record-deleted/record-deleted.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 record in specified table is deleted",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getEventType() {
return "table.recordDelete";
},
generateMeta(body) {
return {
id: body.eventId,
summary: `Record deleted with PK_ID: ${body.data[0].PK_ID}`,
ts: Date.parse(body.eventDate),
};
},
},
sampleEmit,
};
17 changes: 17 additions & 0 deletions components/caspio/sources/record-deleted/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
"eventId": "p0587p",
"messageId": "8ee72cd0-be50-4d6c-84aa-a7524bec6c85",
"webhookId": "k363j2",
"accountId": "",
"secret": "",
"eventDate": "2026-01-16T19:59:13",
"eventType": "table.recordDelete",
"objectName": "New_Table",
"data": [
{
"PK_ID": 1,
"id": "1",
"name": "example"
}
]
}
26 changes: 26 additions & 0 deletions components/caspio/sources/record-updated/record-updated.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import common from "../common/base-webhook.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "caspio-record-updated",
name: "Record Updated (Instant)",

Check warning on line 7 in components/caspio/sources/record-updated/record-updated.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 record in specified table is updated",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getEventType() {
return "table.recordUpdate";
},
generateMeta(body) {
return {
id: body.eventId,
summary: `Record updated with PK_ID: ${body.data[0].PK_ID}`,
ts: Date.parse(body.eventDate),
};
},
},
sampleEmit,
};
17 changes: 17 additions & 0 deletions components/caspio/sources/record-updated/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
"eventId": "l9m8rk",
"messageId": "0f73df53-01f0-479b-853c-9bde29952e05",
"webhookId": "71a8dk",
"accountId": "",
"secret": "",
"eventDate": "2026-01-16T19:56:38",
"eventType": "table.recordUpdate",
"objectName": "New_Table",
"data": [
{
"PK_ID": 1,
"id": "1",
"name": "example"
}
]
}
Loading