-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - adrapid #13708
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 - adrapid #13708
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5c8da69
adrapid init
luancazarine b828d47
[Components] adrapid #13636
luancazarine 4968af3
pnpm update
luancazarine d4c522a
Merge branch 'master' into issue-13636
luancazarine 793c10d
Merge branch 'master' into issue-13636
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
185 changes: 185 additions & 0 deletions
185
components/adrapid/actions/create-banner/create-banner.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,185 @@ | ||
import adrapid from "../../adrapid.app.mjs"; | ||
import { parseObject } from "../../common/utils.mjs"; | ||
|
||
export default { | ||
key: "adrapid-create-banner", | ||
name: "Create Banner", | ||
description: "Generates a new banner using provided data. This action can create different types of banners, such as animated HTML5, image, or video banners. [See the documentation](https://docs.adrapid.com/api/overview)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
adrapid, | ||
templateId: { | ||
propDefinition: [ | ||
adrapid, | ||
"templateId", | ||
], | ||
reloadProps: true, | ||
}, | ||
modes: { | ||
type: "string[]", | ||
label: "Modes", | ||
description: "Modes for the resulting banners, previously set on configuration block.", | ||
options: [ | ||
"html5", | ||
"amp", | ||
"png", | ||
"jpeg", | ||
"pdf", | ||
"webp", | ||
"video", | ||
"gif", | ||
], | ||
reloadProps: true, | ||
optional: true, | ||
}, | ||
overrides: { | ||
type: "object", | ||
label: "Overrides", | ||
description: "With this parameter we override the default template content. We use the name of the item we want to override, valid properties are text, url (for external images) and css. [See the documentation](https://docs.adrapid.com/api/overview).", | ||
optional: true, | ||
}, | ||
sync: { | ||
type: "boolean", | ||
label: "Sync", | ||
description: "Get banner url in the same response. Delay the response until the banner is ready. Usually in a few seconds with a maxtime of two minutes.", | ||
optional: true, | ||
}, | ||
editable: { | ||
type: "boolean", | ||
label: "Editable", | ||
description: "Make banner editable, creating a template that is a copy of the banner.", | ||
optional: true, | ||
}, | ||
excludeBaseSize: { | ||
type: "boolean", | ||
label: "Exclude Base Size", | ||
description: "Exclude base size from the banner. Only applies to multisize banners.", | ||
optional: true, | ||
}, | ||
}, | ||
async additionalProps() { | ||
const props = {}; | ||
if (this.templateId) { | ||
const { sizes } = await this.adrapid.getTemplate({ | ||
templateId: this.templateId, | ||
}); | ||
props.sizeIds = { | ||
type: "string[]", | ||
label: "Size Ids", | ||
description: "The template sizes. To use all of them you can set this parameter to 'all'. If you remove this parameter only the default size of the template will be used.", | ||
reloadProps: true, | ||
optional: true, | ||
options: sizes.map(({ | ||
id: value, name: label, | ||
}) => ({ | ||
value, | ||
label, | ||
})), | ||
}; | ||
} | ||
|
||
if (this.modes) { | ||
if (this.modes.includes("html5")) { | ||
props.html5Packed = { | ||
type: "boolean", | ||
label: "HTML5 Packed", | ||
description: "Set banner in a single file with embedded images.", | ||
}; | ||
props.html5Flexible = { | ||
type: "boolean", | ||
label: "HTML5 Flexible", | ||
description: "Set a flexible banner that will adapt to his container.", | ||
}; | ||
} | ||
if (this.modes.includes("video")) { | ||
props.videoFps = { | ||
type: "integer", | ||
label: "Video FPS", | ||
description: "Frame Per Second of resulting video.", | ||
default: 14, | ||
max: 60, | ||
}; | ||
props.videoCrf = { | ||
type: "integer", | ||
label: "Video CRF", | ||
description: "Constant Rate Factor. Less is more quality.", | ||
default: 18, | ||
max: 60, | ||
}; | ||
props.videoOffset = { | ||
type: "string", | ||
label: "Audio Offset", | ||
description: "Audio offset. Can be negative number.", | ||
}; | ||
props.videoSrc = { | ||
type: "string", | ||
label: "Audio SRC", | ||
description: "URL of the audio file.", | ||
}; | ||
} | ||
if (this.modes.includes("gif")) { | ||
props.gifFps = { | ||
type: "boolean", | ||
label: "GIF FPS", | ||
description: "Frame per second of resulting gif.", | ||
}; | ||
props.gifFrames = { | ||
type: "integer[]", | ||
label: "GIF Frames", | ||
description: "Select specific seconds in the timeline to be used as frames.", | ||
}; | ||
} | ||
} | ||
return props; | ||
}, | ||
async run({ $ }) { | ||
|
||
const modes = {}; | ||
|
||
if (this.modes) { | ||
this.modes.forEach((item) => { | ||
modes[item] = true; | ||
}); | ||
|
||
if (this.modes.includes("html5")) { | ||
modes.html5 = { | ||
packed: this.html5Packed, | ||
flexibe: this.html5Flexible, | ||
}; | ||
} | ||
if (this.modes.includes("video")) { | ||
modes.video = { | ||
fps: this.videoFps, | ||
crf: this.videoCrf, | ||
audio: { | ||
offset: parseInt(this.videoOffset), | ||
src: this.videoSrc, | ||
}, | ||
}; | ||
} | ||
if (this.modes.includes("gif")) { | ||
modes.html5 = { | ||
fps: this.gifFps, | ||
frames: this.gifFrames, | ||
}; | ||
} | ||
} | ||
|
||
const response = await this.adrapid.createBanner({ | ||
$, | ||
data: { | ||
sizeIds: this.sizeIds, | ||
templateId: this.templateId, | ||
modes, | ||
overrides: parseObject(this.overrides), | ||
sync: this.sync, | ||
editable: this.editable, | ||
excludeBaseSize: this.excludeBaseSize, | ||
}, | ||
}); | ||
|
||
$.export("$summary", `Banner created successfully with ID: ${response.id}`); | ||
return response; | ||
}, | ||
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import adrapid from "../../adrapid.app.mjs"; | ||
|
||
export default { | ||
key: "adrapid-get-banner", | ||
name: "Get Banner", | ||
description: "Retrieves a specified banner. This action should be used after a 'create-banner' action to ensure that the banner is fully processed and ready for use. [See the documentation](https://docs.adrapid.com/api/overview)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
adrapid, | ||
bannerId: { | ||
propDefinition: [ | ||
adrapid, | ||
"bannerId", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.adrapid.getBanner({ | ||
$, | ||
bannerId: this.bannerId, | ||
}); | ||
|
||
$.export("$summary", `Successfully retrieved banner: ${response.id}`); | ||
return response; | ||
}, | ||
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,11 +1,126 @@ | ||
import { axios } from "@pipedream/platform"; | ||
import { LIMIT } from "./common/constants.mjs"; | ||
|
||
export default { | ||
type: "app", | ||
app: "adrapid", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
bannerId: { | ||
type: "string", | ||
label: "Banner Id", | ||
description: "The id of the banner.", | ||
async options({ page }) { | ||
const { rows: data } = await this.listBanners({ | ||
params: { | ||
limit: LIMIT, | ||
offset: LIMIT * page, | ||
}, | ||
}); | ||
|
||
return data.map(({ | ||
id: value, name: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})); | ||
}, | ||
}, | ||
templateId: { | ||
type: "string", | ||
label: "Template Id", | ||
description: "The id of the template to create the banner.", | ||
async options({ page }) { | ||
const { rows: data } = await this.listTemplates({ | ||
params: { | ||
limit: LIMIT, | ||
offset: LIMIT * page, | ||
}, | ||
}); | ||
|
||
return data.map(({ | ||
id: value, name: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://api.adrapid.com"; | ||
}, | ||
_headers() { | ||
return { | ||
Authorization: `Bearer ${this.$auth.api_token}`, | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
headers: this._headers(), | ||
...opts, | ||
}); | ||
}, | ||
listBanners(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/banners", | ||
...opts, | ||
}); | ||
}, | ||
listTemplates(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/templates", | ||
...opts, | ||
}); | ||
}, | ||
getTemplate({ templateId }) { | ||
return this._makeRequest({ | ||
path: `/templates/${templateId}`, | ||
}); | ||
}, | ||
getBanner({ | ||
bannerId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/banners/${bannerId}`, | ||
...opts, | ||
}); | ||
}, | ||
createBanner(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/banners", | ||
...opts, | ||
}); | ||
}, | ||
async *paginate({ | ||
fn, params = {}, maxResults = null, ...opts | ||
}) { | ||
let hasMore = false; | ||
let count = 0; | ||
let page = 0; | ||
|
||
do { | ||
params.limit = LIMIT; | ||
params.offset = LIMIT * page++; | ||
const { rows } = await fn({ | ||
params, | ||
...opts, | ||
}); | ||
for (const d of rows) { | ||
yield d; | ||
|
||
if (maxResults && ++count === maxResults) { | ||
return count; | ||
} | ||
} | ||
|
||
hasMore = rows.length; | ||
|
||
} 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const LIMIT = 100; |
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,24 @@ | ||
export const parseObject = (obj) => { | ||
if (!obj) return undefined; | ||
|
||
if (Array.isArray(obj)) { | ||
return obj.map((item) => { | ||
if (typeof item === "string") { | ||
try { | ||
return JSON.parse(item); | ||
} catch (e) { | ||
return item; | ||
} | ||
} | ||
return item; | ||
}); | ||
} | ||
if (typeof obj === "string") { | ||
try { | ||
return JSON.parse(obj); | ||
} catch (e) { | ||
return obj; | ||
} | ||
} | ||
return obj; | ||
}; | ||
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/adrapid", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream Adrapid Components", | ||
"main": "adrapid.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.1" | ||
} | ||
} | ||
} |
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.