-
Notifications
You must be signed in to change notification settings - Fork 5.6k
GrowSurf - new components #19361
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
Open
michelle0927
wants to merge
3
commits into
master
Choose a base branch
from
issue-13339
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
GrowSurf - new components #19361
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 |
|---|---|---|
| @@ -1,11 +1,80 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "growsurf", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| campaignId: { | ||
| type: "string", | ||
| label: "Campaign ID", | ||
| description: "The ID of a campaign", | ||
| async options() { | ||
| const { campaigns } = await this.listCampaigns(); | ||
| return campaigns?.map((campaign) => ({ | ||
| label: campaign.name, | ||
| value: campaign.id, | ||
| })) || []; | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.growsurf.com/v2"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| "Authorization": `Bearer ${this.$auth.api_key}`, | ||
| }, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listCampaigns(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/campaigns", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listParticipants({ | ||
| campaignId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/campaign/${campaignId}/participants`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listReferrals({ | ||
| campaignId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/campaign/${campaignId}/referrals`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| fn, args, resourceKey, max, | ||
| }) { | ||
| args.params = args.params || {}; | ||
| let hasMore = true; | ||
| let count = 0; | ||
| do { | ||
| const response = await fn(args); | ||
| const items = response[resourceKey]; | ||
| if (!items?.length) { | ||
| return; | ||
| } | ||
| for (const item of items) { | ||
| yield item; | ||
| if (max && ++count >= max) { | ||
| return; | ||
| } | ||
| } | ||
| hasMore = response.nextId; | ||
| args.params.nextId = response.nextId; | ||
| } while (hasMore); | ||
| }, | ||
| }, | ||
| }; |
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
25 changes: 25 additions & 0 deletions
25
components/growsurf/sources/campaign-completed/campaign-completed.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,25 @@ | ||
| import common from "../common/base.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "growsurf-campaign-completed", | ||
| name: "Campaign Completed", | ||
| description: "Emit new event when a campaign is completed. [See the documentation](https://docs.growsurf.com/developer-tools/rest-api/api-reference#get-campaigns)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| async getResources() { | ||
| const { campaigns } = await this.growsurf.listCampaigns(); | ||
| return campaigns.filter((campaign) => campaign.status === "COMPLETE"); | ||
| }, | ||
| generateMeta(campaign) { | ||
| return { | ||
| id: campaign.id, | ||
| summary: `Campaign Completed: ${campaign.name}`, | ||
| ts: Date.now(), | ||
| }; | ||
| }, | ||
| }, | ||
| }; | ||
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,49 @@ | ||
| import growsurf from "../../growsurf.app.mjs"; | ||
| import { | ||
| DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError, | ||
| } from "@pipedream/platform"; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default { | ||
| props: { | ||
| growsurf, | ||
| 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); | ||
| }, | ||
| getResources() { | ||
| throw new ConfigurationError("getResources is not implemented"); | ||
| }, | ||
| generateMeta() { | ||
| throw new ConfigurationError("generateMeta is not implemented"); | ||
| }, | ||
| async processEvent(max) { | ||
| const results = await this.getResources(max); | ||
| if (!results.length) { | ||
| return; | ||
| } | ||
| for (const result of results) { | ||
| const meta = this.generateMeta(result); | ||
| this.$emit(result, meta); | ||
| } | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.processEvent(10); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.processEvent(); | ||
| }, | ||
| }; | ||
58 changes: 58 additions & 0 deletions
58
components/growsurf/sources/new-campaign-referral-made/new-campaign-referral-made.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,58 @@ | ||
| import common from "../common/base.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "growsurf-new-campaign-referral-made", | ||
| name: "New Campaign Referral Made", | ||
| description: "Emit new event when a new referral is made for a campaign. [See the documentation](https://docs.growsurf.com/developer-tools/rest-api/api-reference#get-referrals-and-invites)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| ...common.props, | ||
| campaignId: { | ||
| propDefinition: [ | ||
| common.props.growsurf, | ||
| "campaignId", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| ...common.methods, | ||
| async getResources(max) { | ||
| const results = this.growsurf.paginate({ | ||
| fn: this.growsurf.listReferrals, | ||
| args: { | ||
| campaignId: this.campaignId, | ||
| params: { | ||
| sortBy: "createdAt", | ||
| desc: true, | ||
| }, | ||
| }, | ||
| resourceKey: "referrals", | ||
| max, | ||
| }); | ||
| const referrals = []; | ||
| const lastTs = this._getLastTs(); | ||
| let maxTs = lastTs; | ||
| for await (const referral of results) { | ||
| const ts = referral.createdAt; | ||
| if (ts > lastTs) { | ||
| referrals.push(referral); | ||
| maxTs = Math.max(ts, maxTs); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| this._setLastTs(maxTs); | ||
| return referrals; | ||
| }, | ||
| generateMeta(referral) { | ||
| return { | ||
| id: referral.id, | ||
| summary: `New Campaign Referral Made: ${referral.email || referral.id}`, | ||
| ts: referral.createdAt, | ||
| }; | ||
| }, | ||
| }, | ||
| }; |
61 changes: 61 additions & 0 deletions
61
components/growsurf/sources/new-participant-added/new-participant-added.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,61 @@ | ||
| import common from "../common/base.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "growsurf-new-participant-added", | ||
| name: "New Participant Added", | ||
| description: "Emit new event when a new participant is added to a campaign. [See the documentation](https://docs.growsurf.com/developer-tools/rest-api/api-reference#get-participants)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| ...common.props, | ||
| campaignId: { | ||
| propDefinition: [ | ||
| common.props.growsurf, | ||
| "campaignId", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| ...common.methods, | ||
| async getResources(max) { | ||
| const results = this.growsurf.paginate({ | ||
| fn: this.growsurf.listParticipants, | ||
| args: { | ||
| campaignId: this.campaignId, | ||
| params: { | ||
| limit: 100, | ||
| }, | ||
| }, | ||
| resourceKey: "participants", | ||
| }); | ||
| const participants = []; | ||
| const lastTs = this._getLastTs(); | ||
| let maxTs = lastTs; | ||
| for await (const participant of results) { | ||
| const ts = participant.createdAt; | ||
| if (ts > lastTs) { | ||
| participants.push(participant); | ||
| maxTs = Math.max(ts, maxTs); | ||
| } | ||
| } | ||
| this._setLastTs(maxTs); | ||
| if (max && participants.length > max) { | ||
| participants.length = max; | ||
| } | ||
| return participants; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| generateMeta(participant) { | ||
| const name = [ | ||
| participant.firstName, | ||
| participant.lastName, | ||
| ].filter(Boolean).join(" ") || participant.email || participant.id; | ||
| return { | ||
| id: participant.id, | ||
| summary: `New Participant Added: ${name}`, | ||
| ts: participant.createdAt, | ||
| }; | ||
| }, | ||
| }, | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.