-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Upgrade Chat - new components #19135
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
| 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
31
components/upgrade_chat/actions/get-product/get-product.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,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
42
components/upgrade_chat/actions/list-orders/list-orders.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,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
42
components/upgrade_chat/actions/list-products/list-products.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,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; | ||
| }, | ||
| }; |
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,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(); | ||
| }, | ||
| }; | ||
20 changes: 20 additions & 0 deletions
20
components/upgrade_chat/sources/new-order-created/new-order-created.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,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`; | ||
| }, | ||
| }, | ||
| }; |
20 changes: 20 additions & 0 deletions
20
components/upgrade_chat/sources/new-product-created/new-product-created.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,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
23
components/upgrade_chat/sources/order-updated/order-updated.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,23 @@ | ||
| import common from "../common/base.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "upgrade_chat-order-updated", | ||
| name: "Order Updated", | ||
| 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"; | ||
| }, | ||
| }, | ||
| }; | ||
23 changes: 23 additions & 0 deletions
23
components/upgrade_chat/sources/product-updated/product-updated.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,23 @@ | ||
| import common from "../common/base.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "upgrade_chat-product-updated", | ||
| name: "Product Updated", | ||
| 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"; | ||
| }, | ||
| }, | ||
| }; | ||
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.