Skip to content

Commit f0e72d9

Browse files
authored
Upgrade Chat - new components (#19135)
* new components * pnpm-lock.yaml * updates
1 parent cf14239 commit f0e72d9

File tree

12 files changed

+683
-82
lines changed

12 files changed

+683
-82
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import upgradeChat from "../../upgrade_chat.app.mjs";
2+
3+
export default {
4+
key: "upgrade_chat-get-order",
5+
name: "Get Order",
6+
description: "Get details of an order. [See the documentation](https://upgrade.chat/developers/documentation)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
upgradeChat,
16+
orderUuid: {
17+
propDefinition: [
18+
upgradeChat,
19+
"orderUuid",
20+
],
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.upgradeChat.getOrder({
25+
$,
26+
orderUuid: this.orderUuid,
27+
});
28+
$.export("$summary", `Successfully retrieved the details for order with ID: ${this.orderUuid}`);
29+
return response;
30+
},
31+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import upgradeChat from "../../upgrade_chat.app.mjs";
2+
3+
export default {
4+
key: "upgrade_chat-get-product",
5+
name: "Get Product",
6+
description: "Get details of a product. [See the documentation](https://upgrade.chat/developers/documentation)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
upgradeChat,
16+
productUuid: {
17+
propDefinition: [
18+
upgradeChat,
19+
"productUuid",
20+
],
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.upgradeChat.getProduct({
25+
$,
26+
productUuid: this.productUuid,
27+
});
28+
$.export("$summary", `Successfully retrieved the details for product with ID: ${this.productUuid}`);
29+
return response;
30+
},
31+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import upgradeChat from "../../upgrade_chat.app.mjs";
2+
3+
export default {
4+
key: "upgrade_chat-list-orders",
5+
name: "List Orders",
6+
description: "Retrieve a list of orders. [See the documentation](https://upgrade.chat/developers/documentation)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
upgradeChat,
16+
limit: {
17+
propDefinition: [
18+
upgradeChat,
19+
"limit",
20+
],
21+
},
22+
offset: {
23+
propDefinition: [
24+
upgradeChat,
25+
"offset",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.upgradeChat.listOrders({
31+
$,
32+
params: {
33+
limit: this.limit,
34+
offset: this.offset,
35+
},
36+
});
37+
$.export("$summary", `Successfully retrieved ${response?.data?.length} order${response?.data?.length === 1
38+
? ""
39+
: "s"}`);
40+
return response;
41+
},
42+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import upgradeChat from "../../upgrade_chat.app.mjs";
2+
3+
export default {
4+
key: "upgrade_chat-list-products",
5+
name: "List Products",
6+
description: "Retrieve a list of products. [See the documentation](https://upgrade.chat/developers/documentation)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
upgradeChat,
16+
limit: {
17+
propDefinition: [
18+
upgradeChat,
19+
"limit",
20+
],
21+
},
22+
offset: {
23+
propDefinition: [
24+
upgradeChat,
25+
"offset",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.upgradeChat.listProducts({
31+
$,
32+
params: {
33+
limit: this.limit,
34+
offset: this.offset,
35+
},
36+
});
37+
$.export("$summary", `Successfully retrieved ${response?.data?.length} product${response?.data?.length === 1
38+
? ""
39+
: "s"}`);
40+
return response;
41+
},
42+
};

components/upgrade_chat/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/upgrade_chat",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Upgrade.chat Components",
55
"main": "upgrade_chat.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.1"
1417
}
15-
}
18+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import upgradeChat from "../../upgrade_chat.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
4+
export default {
5+
props: {
6+
upgradeChat,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
methods: {
16+
_getLastTs() {
17+
return this.db.get("lastTs") || 0;
18+
},
19+
_setLastTs(lastTs) {
20+
this.db.set("lastTs", lastTs);
21+
},
22+
getResourceFn() {
23+
throw new Error("getResourceFn is not implemented");
24+
},
25+
getSummary() {
26+
throw new Error("getSummary is not implemented");
27+
},
28+
getParams() {
29+
return {};
30+
},
31+
getTsField() {
32+
return "created";
33+
},
34+
generateMeta(item) {
35+
const ts = Date.parse(item[this.getTsField()]);
36+
return {
37+
id: `${item.uuid}-${ts}`,
38+
summary: this.getSummary(item),
39+
ts,
40+
};
41+
},
42+
async processEvent(max) {
43+
const lastTs = this._getLastTs();
44+
let maxTs = lastTs;
45+
const resourceFn = this.getResourceFn();
46+
const params = this.getParams();
47+
const tsField = this.getTsField();
48+
49+
const items = this.upgradeChat.paginate({
50+
fn: resourceFn,
51+
params,
52+
});
53+
54+
let results = [];
55+
for await (const item of items) {
56+
const ts = Date.parse(item[tsField]);
57+
if (ts > lastTs) {
58+
results.push(item);
59+
maxTs = Math.max(ts, maxTs);
60+
}
61+
}
62+
this._setLastTs(maxTs);
63+
64+
if (max && results.length > max) {
65+
results = results.slice(-1 * max);
66+
}
67+
68+
for (const item of results) {
69+
const meta = this.generateMeta(item);
70+
this.$emit(item, meta);
71+
}
72+
},
73+
},
74+
hooks: {
75+
async deploy() {
76+
await this.processEvent(10);
77+
},
78+
},
79+
async run() {
80+
await this.processEvent();
81+
},
82+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "upgrade_chat-new-order-created",
6+
name: "New Order Created",
7+
description: "Emit new event when an order is created. [See the documentation](https://upgrade.chat/developers/documentation)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getResourceFn() {
14+
return this.upgradeChat.listOrders;
15+
},
16+
getSummary(order) {
17+
return `Order ${order.uuid} created`;
18+
},
19+
},
20+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "upgrade_chat-new-product-created",
6+
name: "New Product Created",
7+
description: "Emit new event when a product is created. [See the documentation](https://upgrade.chat/developers/documentation)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getResourceFn() {
14+
return this.upgradeChat.listProducts;
15+
},
16+
getSummary(product) {
17+
return `Product ${product.name} created`;
18+
},
19+
},
20+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "upgrade_chat-order-updated",
6+
name: "Order Updated",
7+
description: "Emit new event when an order is updated. [See the documentation](https://upgrade.chat/developers/documentation)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getResourceFn() {
14+
return this.upgradeChat.listOrders;
15+
},
16+
getSummary(order) {
17+
return `Order ${order.uuid} updated`;
18+
},
19+
getTsField() {
20+
return "updated";
21+
},
22+
},
23+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "upgrade_chat-product-updated",
6+
name: "Product Updated",
7+
description: "Emit new event when a product is updated. [See the documentation](https://upgrade.chat/developers/documentation)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getResourceFn() {
14+
return this.upgradeChat.listProducts;
15+
},
16+
getSummary(product) {
17+
return `Product ${product.name} updated`;
18+
},
19+
getTsField() {
20+
return "updated";
21+
},
22+
},
23+
};

0 commit comments

Comments
 (0)