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
31 changes: 31 additions & 0 deletions components/upgrade_chat/actions/get-order/get-order.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import upgradeChat from "../../upgrade_chat.app.mjs";

export default {
key: "upgrade_chat-get-order",
name: "Get Order",
description: "Get details of an order. [See the documentation](https://upgrade.chat/developers/documentation)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
upgradeChat,
orderUuid: {
propDefinition: [
upgradeChat,
"orderUuid",
],
},
},
async run({ $ }) {
const response = await this.upgradeChat.getOrder({
$,
orderUuid: this.orderUuid,
});
$.export("$summary", `Successfully retrieved the details for order with ID: ${this.orderUuid}`);
return response;
},
};
31 changes: 31 additions & 0 deletions components/upgrade_chat/actions/get-product/get-product.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import upgradeChat from "../../upgrade_chat.app.mjs";

export default {
key: "upgrade_chat-get-product",
name: "Get Product",
description: "Get details of a product. [See the documentation](https://upgrade.chat/developers/documentation)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
upgradeChat,
productUuid: {
propDefinition: [
upgradeChat,
"productUuid",
],
},
},
async run({ $ }) {
const response = await this.upgradeChat.getProduct({
$,
productUuid: this.productUuid,
});
$.export("$summary", `Successfully retrieved the details for product with ID: ${this.productUuid}`);
return response;
},
};
42 changes: 42 additions & 0 deletions components/upgrade_chat/actions/list-orders/list-orders.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import upgradeChat from "../../upgrade_chat.app.mjs";

export default {
key: "upgrade_chat-list-orders",
name: "List Orders",
description: "Retrieve a list of orders. [See the documentation](https://upgrade.chat/developers/documentation)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
upgradeChat,
limit: {
propDefinition: [
upgradeChat,
"limit",
],
},
offset: {
propDefinition: [
upgradeChat,
"offset",
],
},
},
async run({ $ }) {
const response = await this.upgradeChat.listOrders({
$,
params: {
limit: this.limit,
offset: this.offset,
},
});
$.export("$summary", `Successfully retrieved ${response?.data?.length} order${response?.data?.length === 1
? ""
: "s"}`);
return response;
},
};
42 changes: 42 additions & 0 deletions components/upgrade_chat/actions/list-products/list-products.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import upgradeChat from "../../upgrade_chat.app.mjs";

export default {
key: "upgrade_chat-list-products",
name: "List Products",
description: "Retrieve a list of products. [See the documentation](https://upgrade.chat/developers/documentation)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
upgradeChat,
limit: {
propDefinition: [
upgradeChat,
"limit",
],
},
offset: {
propDefinition: [
upgradeChat,
"offset",
],
},
},
async run({ $ }) {
const response = await this.upgradeChat.listProducts({
$,
params: {
limit: this.limit,
offset: this.offset,
},
});
$.export("$summary", `Successfully retrieved ${response?.data?.length} product${response?.data?.length === 1
? ""
: "s"}`);
return response;
},
};
7 changes: 5 additions & 2 deletions components/upgrade_chat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/upgrade_chat",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Upgrade.chat Components",
"main": "upgrade_chat.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"
}
}
}
82 changes: 82 additions & 0 deletions components/upgrade_chat/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import upgradeChat from "../../upgrade_chat.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
props: {
upgradeChat,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastTs() {
return this.db.get("lastTs") || 0;
},
_setLastTs(lastTs) {
this.db.set("lastTs", lastTs);
},
getResourceFn() {
throw new Error("getResourceFn is not implemented");
},
getSummary() {
throw new Error("getSummary is not implemented");
},
getParams() {
return {};
},
getTsField() {
return "created";
},
generateMeta(item) {
const ts = Date.parse(item[this.getTsField()]);
return {
id: `${item.uuid}-${ts}`,
summary: this.getSummary(item),
ts,
};
},
async processEvent(max) {
const lastTs = this._getLastTs();
let maxTs = lastTs;
const resourceFn = this.getResourceFn();
const params = this.getParams();
const tsField = this.getTsField();

const items = this.upgradeChat.paginate({
fn: resourceFn,
params,
});

let results = [];
for await (const item of items) {
const ts = Date.parse(item[tsField]);
if (ts > lastTs) {
results.push(item);
maxTs = Math.max(ts, maxTs);
}
}
this._setLastTs(maxTs);

if (max && results.length > max) {
results = results.slice(-1 * max);
}

for (const item of results) {
const meta = this.generateMeta(item);
this.$emit(item, meta);
}
},
},
hooks: {
async deploy() {
await this.processEvent(10);
},
},
async run() {
await this.processEvent();
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import common from "../common/base.mjs";

export default {
...common,
key: "upgrade_chat-new-order-created",
name: "New Order Created",
description: "Emit new event when an order is created. [See the documentation](https://upgrade.chat/developers/documentation)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getResourceFn() {
return this.upgradeChat.listOrders;
},
getSummary(order) {
return `Order ${order.uuid} created`;
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import common from "../common/base.mjs";

export default {
...common,
key: "upgrade_chat-new-product-created",
name: "New Product Created",
description: "Emit new event when a product is created. [See the documentation](https://upgrade.chat/developers/documentation)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getResourceFn() {
return this.upgradeChat.listProducts;
},
getSummary(product) {
return `Product ${product.name} created`;
},
},
};
23 changes: 23 additions & 0 deletions components/upgrade_chat/sources/order-updated/order-updated.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import common from "../common/base.mjs";

export default {
...common,
key: "upgrade_chat-order-updated",
name: "Order Updated",

Check warning on line 6 in components/upgrade_chat/sources/order-updated/order-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 an order is updated. [See the documentation](https://upgrade.chat/developers/documentation)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getResourceFn() {
return this.upgradeChat.listOrders;
},
getSummary(order) {
return `Order ${order.uuid} updated`;
},
getTsField() {
return "updated";
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import common from "../common/base.mjs";

export default {
...common,
key: "upgrade_chat-product-updated",
name: "Product Updated",

Check warning on line 6 in components/upgrade_chat/sources/product-updated/product-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 product is updated. [See the documentation](https://upgrade.chat/developers/documentation)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getResourceFn() {
return this.upgradeChat.listProducts;
},
getSummary(product) {
return `Product ${product.name} updated`;
},
getTsField() {
return "updated";
},
},
};
Loading
Loading