-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New Components - easypromos #15201
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
New Components - easypromos #15201
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b79de9b
easypromos init
luancazarine 45e5a20
[Components] easypromos #15197
luancazarine 5340762
add info prop
luancazarine 44daab4
pnpm update
luancazarine 870266f
Merge branch 'master' into issue-15197
luancazarine 9ebfda5
pnpm update
luancazarine 69389c5
some adjusts
luancazarine bd03556
some adjusts
luancazarine 310e426
Merge branch 'master' into issue-15197
luancazarine 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
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ export default { | |
console.log(Object.keys(this.$auth)); | ||
}, | ||
}, | ||
}; | ||
}; |
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,139 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "easypromos", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
userId: { | ||
type: "integer", | ||
label: "User ID", | ||
description: "The ID of the user", | ||
async options({ | ||
promotionId, prevContext, | ||
}) { | ||
const { | ||
items, paging, | ||
} = await this.getUsers({ | ||
promotionId, | ||
params: { | ||
next_cursor: prevContext.nextCursor, | ||
}, | ||
}); | ||
return { | ||
options: items.map(({ | ||
id: value, email: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})), | ||
context: { | ||
nextCursor: paging.next_cursor, | ||
}, | ||
}; | ||
}, | ||
}, | ||
promotionId: { | ||
type: "integer", | ||
label: "Promotion ID", | ||
description: "The ID of the promotion", | ||
async options({ prevContext }) { | ||
const { | ||
items, paging, | ||
} = await this.getPromotions({ | ||
params: { | ||
next_cursor: prevContext.nextCursor, | ||
}, | ||
}); | ||
return { | ||
options: items.map(({ | ||
id, title, internal_ref: ref, | ||
}) => ({ | ||
label: ref || title, | ||
value: parseInt(id), | ||
})), | ||
context: { | ||
nextCursor: paging.next_cursor, | ||
}, | ||
}; | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://api.easypromosapp.com/v2"; | ||
}, | ||
_headers() { | ||
return { | ||
Authorization: `Bearer ${this.$auth.api_key}`, | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
headers: this._headers(), | ||
...opts, | ||
}); | ||
}, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getCoinTransactions({ | ||
promotionId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/coin_transactions/${promotionId}`, | ||
...opts, | ||
}); | ||
}, | ||
getUsers({ | ||
promotionId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/users/${promotionId}`, | ||
...opts, | ||
}); | ||
}, | ||
getParticipations({ | ||
promotionId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/participations/${promotionId}`, | ||
...opts, | ||
}); | ||
}, | ||
getPromotions(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/promotions", | ||
...opts, | ||
}); | ||
}, | ||
async *paginate({ | ||
fn, params = {}, maxResults = null, ...opts | ||
}) { | ||
let hasMore = false; | ||
let count = 0; | ||
let nextCursor = null; | ||
|
||
do { | ||
params.next_cursor = nextCursor; | ||
const { | ||
items, | ||
paging: { next_cursor }, | ||
} = await fn({ | ||
params, | ||
...opts, | ||
}); | ||
for (const d of items) { | ||
yield d; | ||
|
||
if (maxResults && ++count === maxResults) { | ||
return count; | ||
} | ||
} | ||
|
||
nextCursor = next_cursor; | ||
hasMore = nextCursor; | ||
|
||
} while (hasMore); | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
}; | ||
}; |
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,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/easypromos", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream Easypromos Components", | ||
"main": "easypromos.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} | ||
} |
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,77 @@ | ||
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
import easypromos from "../../easypromos.app.mjs"; | ||
|
||
export default { | ||
props: { | ||
easypromos, | ||
db: "$.service.db", | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
}, | ||
}, | ||
info: { | ||
Check warning on line 14 in components/easypromos/sources/common/base.mjs
|
||
type: "alert", | ||
alertType: "info", | ||
content: "The Easypromos API only works with \"White Label\" promotions, any other type will not appear in the list.", | ||
}, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
promotionId: { | ||
propDefinition: [ | ||
easypromos, | ||
"promotionId", | ||
], | ||
}, | ||
}, | ||
methods: { | ||
_getLastId() { | ||
return this.db.get("lastId") || 0; | ||
}, | ||
_setLastId(lastId) { | ||
this.db.set("lastId", lastId); | ||
}, | ||
getOpts() { | ||
return {}; | ||
}, | ||
async emitEvent(maxResults = false) { | ||
const lastId = this._getLastId(); | ||
|
||
const response = this.easypromos.paginate({ | ||
fn: this.getFunction(), | ||
...this.getOpts(), | ||
params: { | ||
order: "created_desc", | ||
}, | ||
}); | ||
|
||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let responseArray = []; | ||
for await (const item of response) { | ||
if (item.id <= lastId) break; | ||
responseArray.push(item); | ||
} | ||
|
||
if (responseArray.length) { | ||
if (maxResults && (responseArray.length > maxResults)) { | ||
responseArray.length = maxResults; | ||
} | ||
this._setLastId(responseArray[0].id); | ||
} | ||
|
||
for (const item of responseArray.reverse()) { | ||
this.$emit(item, { | ||
id: item.id || item.transaction.id, | ||
summary: this.getSummary(item), | ||
ts: Date.parse(item.created || new Date()), | ||
}); | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
hooks: { | ||
async deploy() { | ||
await this.emitEvent(25); | ||
}, | ||
}, | ||
async run() { | ||
await this.emitEvent(); | ||
}, | ||
}; |
29 changes: 29 additions & 0 deletions
29
components/easypromos/sources/new-coin-transaction/new-coin-transaction.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,29 @@ | ||
import common from "../common/base.mjs"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "easypromos-new-coin-transaction", | ||
name: "New Coin Transaction", | ||
description: "Emit new event when a user earns or spends coins.", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
methods: { | ||
...common.methods, | ||
getFunction() { | ||
return this.easypromos.getCoinTransactions; | ||
}, | ||
getOpts() { | ||
return { | ||
promotionId: this.promotionId, | ||
}; | ||
}, | ||
getSummary({ | ||
transaction, user, | ||
}) { | ||
return `Coin transaction: ${transaction.amount} for user ${user.email}`; | ||
}, | ||
}, | ||
sampleEmit, | ||
}; |
54 changes: 54 additions & 0 deletions
54
components/easypromos/sources/new-coin-transaction/test-event.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,54 @@ | ||
export default { | ||
"transaction": { | ||
"id": 1, | ||
"user_id": 1, | ||
"promotion_id": 1, | ||
"coin_id": 1, | ||
"coin_name": "Points", | ||
"amount": 5, | ||
"balance": 5, | ||
"created": "2019-08-24T14:15:22Z", | ||
"transaction_type": 1, | ||
"reason": "Earned for participating in a stage", | ||
"extra": "string" | ||
}, | ||
"user": { | ||
"id": 1, | ||
"promotion_id": 1, | ||
"first_name": "John", | ||
"last_name": "Smith", | ||
"nickname": "jsmith", | ||
"login_type": "email", | ||
"social_id": "string", | ||
"external_id": "string", | ||
"status": 0, | ||
"email": "[email protected]", | ||
"phone": "string", | ||
"birthday": "2019-08-24", | ||
"created": "2019-08-24T14:15:22Z", | ||
"avatar_img": "http://example.com", | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"language": "ara", | ||
"country": "FR", | ||
"custom_properties": [ | ||
{ | ||
"id": 1, | ||
"title": "Postal code", | ||
"ref": "postalcode", | ||
"value": "PC98776" | ||
} | ||
], | ||
"meta_data": { | ||
"utm_source": "instagram", | ||
"utm_medium": "ads", | ||
"utm_campaign": "campaign-week1", | ||
"referral_url": "http://example.com", | ||
"ip": "192.168.0.1", | ||
"user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148", | ||
"legals": { | ||
"terms_url": "https://a.cstmapp.com/promo_terms/919755", | ||
"privacy_url": "https://a.cstmapp.com/policy/987543", | ||
"accepted_cookies": 1 | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
components/easypromos/sources/new-participation/new-participation.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,27 @@ | ||
import common from "../common/base.mjs"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "easypromos-new-participation", | ||
name: "New Participation Submitted", | ||
description: "Emit new event when a registered user submits a participation in the promotion.", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
methods: { | ||
...common.methods, | ||
getFunction() { | ||
return this.easypromos.getParticipations; | ||
}, | ||
getOpts() { | ||
return { | ||
promotionId: this.promotionId, | ||
}; | ||
}, | ||
getSummary(participation) { | ||
return `New Participation: ${participation.id}`; | ||
}, | ||
}, | ||
sampleEmit, | ||
}; |
19 changes: 19 additions & 0 deletions
19
components/easypromos/sources/new-participation/test-event.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,19 @@ | ||
export default { | ||
"id": 1, | ||
"promotion_id": 1, | ||
"stage_id": 1, | ||
"user_id": 1, | ||
"created": "2019-08-24T14:15:22Z", | ||
"ip": "192.168.0.1", | ||
"user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/201.0.429950705 Mobile/15E148 Safari/604.1", | ||
"points": 786.43, | ||
"data": [ | ||
{ | ||
"ref": "Question1", | ||
"title": "Pick your favorite city", | ||
"values": [ | ||
"Barcelona" | ||
] | ||
} | ||
] | ||
} |
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.