diff --git a/components/anchor_browser/actions/create-profile/create-profile.mjs b/components/anchor_browser/actions/create-profile/create-profile.mjs new file mode 100644 index 0000000000000..5dab1e709e318 --- /dev/null +++ b/components/anchor_browser/actions/create-profile/create-profile.mjs @@ -0,0 +1,66 @@ +import app from "../../anchor_browser.app.mjs"; + +export default { + key: "anchor_browser-create-profile", + name: "Create Profile", + description: "Creates a new profile from a session. A Profile stores cookies, local storage, and cache. [See the documentation](https://docs.anchorbrowser.io/api-reference/profiles/create-profile).", + version: "0.0.1", + type: "action", + props: { + app, + name: { + propDefinition: [ + app, + "name", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + source: { + propDefinition: [ + app, + "source", + ], + }, + sessionId: { + propDefinition: [ + app, + "sessionId", + ], + }, + }, + methods: { + createProfile(args = {}) { + return this.app.post({ + path: "/profiles", + ...args, + }); + }, + }, + async run({ $ }) { + const { + createProfile, + name, + description, + source, + sessionId, + } = this; + + const response = await createProfile({ + $, + data: { + name, + description, + source, + session_id: sessionId, + }, + }); + + $.export("$summary", "Successfully created profile."); + return response; + }, +}; diff --git a/components/anchor_browser/actions/delete-profile/delete-profile.mjs b/components/anchor_browser/actions/delete-profile/delete-profile.mjs new file mode 100644 index 0000000000000..e83d8aa86c58e --- /dev/null +++ b/components/anchor_browser/actions/delete-profile/delete-profile.mjs @@ -0,0 +1,43 @@ +import app from "../../anchor_browser.app.mjs"; + +export default { + key: "anchor_browser-delete-profile", + name: "Delete Profile", + description: "Deletes an existing profile by its name. [See the documentation](https://docs.anchorbrowser.io/api-reference/profiles/delete-profile).", + version: "0.0.1", + type: "action", + props: { + app, + profileName: { + description: "The name of the profile to delete.", + propDefinition: [ + app, + "profileName", + ], + }, + }, + methods: { + deleteProfile({ + profileName, ...args + } = {}) { + return this.app.delete({ + path: `/profiles/${encodeURIComponent(profileName)}`, + ...args, + }); + }, + }, + async run({ $ }) { + const { + deleteProfile, + profileName, + } = this; + + const response = await deleteProfile({ + $, + profileName, + }); + + $.export("$summary", "Successfully deleted profile."); + return response; + }, +}; diff --git a/components/anchor_browser/actions/start-browser/start-browser.mjs b/components/anchor_browser/actions/start-browser/start-browser.mjs new file mode 100644 index 0000000000000..7a855d33e9e0a --- /dev/null +++ b/components/anchor_browser/actions/start-browser/start-browser.mjs @@ -0,0 +1,144 @@ +import app from "../../anchor_browser.app.mjs"; + +export default { + key: "anchor_browser-start-browser", + name: "Start Browser", + description: "Allocates a new browser session for the user, with optional configurations for ad-blocking, captcha solving, proxy usage, and idle timeout. [See the documentation](https://docs.anchorbrowser.io/api-reference/browser-sessions/start-browser).", + version: "0.0.1", + type: "action", + props: { + app, + adblockConfigActive: { + type: "boolean", + label: "Adblock Configuration - Active", + description: "Whether adblock configuration is active", + }, + adblockConfigPopupBlockingActive: { + type: "boolean", + label: "Adblock Configuration - Popup Blocking Active", + description: "Whether popup blocking is active", + }, + captchaConfigActive: { + type: "boolean", + label: "Captcha Configuration - Active", + description: "Whether captcha configuration is active", + }, + headless: { + type: "boolean", + label: "Headless", + description: "Whether browser should be headless or headfull.", + }, + proxyConfigType: { + type: "string", + label: "Proxy Configuration - Type", + description: "The type of proxy configuration to use. Eg. `anchor_residential`.", + optional: true, + }, + proxyConfigActive: { + type: "boolean", + label: "Proxy Configuration - Active", + description: "Whether proxy configuration is active", + optional: true, + }, + recordingActive: { + type: "boolean", + label: "Recording - Active", + description: "Whether recording is active", + optional: true, + }, + profileName: { + description: "The name of the profile to use for the browser session.", + propDefinition: [ + app, + "profileName", + ], + }, + profilePersist: { + type: "boolean", + label: "Profile - Persist", + description: "Whether the profile should persist after the session ends.", + }, + viewportWidth: { + type: "integer", + label: "Viewport - Width", + description: "The width of the viewport", + }, + viewportHeight: { + type: "integer", + label: "Viewport - Height", + description: "The height of the viewport", + }, + timeout: { + type: "string", + label: "Timeout", + description: "Maximum amount of time (in minutes) for the browser to run, before terminating. Defaults to `-1`, which disables the global timeout mechanism.", + optional: true, + }, + idleTimeout: { + type: "string", + label: "Idle Timeout", + description: "The amount of time (in minutes) the session waits for new connections after all others are closed before stopping. Defaults to `1`. Setting it to `-1` let the browser session continue forever [**CAUTION** - Keep track of long living sessions and manually kill them].", + optional: true, + }, + }, + methods: { + startBrowserSession(args = {}) { + return this.app.post({ + path: "/sessions", + ...args, + }); + }, + }, + async run({ $ }) { + const { + startBrowserSession, + adblockConfigActive, + adblockConfigPopupBlockingActive, + captchaConfigActive, + headless, + proxyConfigType, + proxyConfigActive, + recordingActive, + profileName, + profilePersist, + viewportWidth, + viewportHeight, + timeout, + idleTimeout, + } = this; + + const response = await startBrowserSession({ + $, + data: { + adblock_config: { + active: adblockConfigActive, + popup_blocking_active: adblockConfigPopupBlockingActive, + }, + captcha_config: { + active: captchaConfigActive, + }, + headless, + proxy_config: { + type: proxyConfigType, + active: proxyConfigActive, + }, + recording: { + active: recordingActive, + }, + profile: { + name: profileName, + persist: profilePersist, + }, + viewport: { + width: viewportWidth, + height: viewportHeight, + }, + timeout, + idle_timeout: idleTimeout, + }, + }); + + $.export("$summary", "Successfully started browser session."); + return response; + }, +}; diff --git a/components/anchor_browser/actions/update-profile/update-profile.mjs b/components/anchor_browser/actions/update-profile/update-profile.mjs new file mode 100644 index 0000000000000..ab41f0fc4ce2c --- /dev/null +++ b/components/anchor_browser/actions/update-profile/update-profile.mjs @@ -0,0 +1,68 @@ +import app from "../../anchor_browser.app.mjs"; + +export default { + key: "anchor_browser-update-profile", + name: "Update Profile", + description: "Updates the description or data of an existing profile using a session. [See the documentation](https://docs.anchorbrowser.io/api-reference/profiles/update-profile).", + version: "0.0.1", + type: "action", + props: { + app, + profileName: { + propDefinition: [ + app, + "profileName", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + source: { + propDefinition: [ + app, + "source", + ], + }, + sessionId: { + propDefinition: [ + app, + "sessionId", + ], + }, + }, + methods: { + updateProfile({ + profileName, ...args + } = {}) { + return this.app.put({ + path: `/profiles/${encodeURIComponent(profileName)}`, + ...args, + }); + }, + }, + async run({ $ }) { + const { + updateProfile, + profileName, + description, + source, + sessionId, + } = this; + + const response = await updateProfile({ + $, + profileName, + data: { + description, + source, + session_id: sessionId, + }, + }); + + $.export("$summary", "Successfully updated profile."); + return response; + }, +}; diff --git a/components/anchor_browser/anchor_browser.app.mjs b/components/anchor_browser/anchor_browser.app.mjs index e56fe6fa9191c..745302711b783 100644 --- a/components/anchor_browser/anchor_browser.app.mjs +++ b/components/anchor_browser/anchor_browser.app.mjs @@ -1,11 +1,96 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "anchor_browser", - propDefinitions: {}, + propDefinitions: { + name: { + type: "string", + label: "Profile Name", + description: "The name of the profile.", + }, + description: { + type: "string", + label: "Profile Description", + description: "The description of the profile.", + optional: true, + }, + source: { + type: "string", + label: "Source", + description: "The source of the profile data. currently only `session` is supported.", + options: [ + "session", + ], + default: "session", + }, + sessionId: { + type: "string", + label: "Session ID", + description: "The session ID is required if the source is set to session. The session must be running, and the profile will be stored once the session terminates.", + async options() { + const sessions = await this.listSessions(); + return sessions.map(({ session_id: value }) => value); + }, + }, + profileName: { + type: "string", + label: "Profile Name", + description: "The name of the profile to update.", + async options() { + const { data: profiles } = await this.listProfiles(); + return profiles.map(({ name: value }) => value); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + return `https://api.anchorbrowser.io/api${path}`; + }, + getHeaders(headers) { + return { + ...headers, + "anchor-api-key": this.$auth.api_key, + }; + }, + _makeRequest({ + $ = this, path, headers, ...args + } = {}) { + return axios($, { + ...args, + url: this.getUrl(path), + headers: this.getHeaders(headers), + }); + }, + post(args = {}) { + return this._makeRequest({ + method: "POST", + ...args, + }); + }, + put(args = {}) { + return this._makeRequest({ + method: "PUT", + ...args, + }); + }, + delete(args = {}) { + return this._makeRequest({ + method: "DELETE", + ...args, + }); + }, + listSessions(args = {}) { + return this._makeRequest({ + path: "/sessions/active", + ...args, + }); + }, + listProfiles(args = {}) { + return this._makeRequest({ + path: "/profiles", + ...args, + }); }, }, }; diff --git a/components/anchor_browser/package.json b/components/anchor_browser/package.json index 1f3ec194f0af0..e44953f685a56 100644 --- a/components/anchor_browser/package.json +++ b/components/anchor_browser/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/anchor_browser", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Anchor Browser Components", "main": "anchor_browser.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 25f2f4f8316b0..41ca05c1c7ed7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -796,7 +796,11 @@ importers: specifier: ^8.3.2 version: 8.3.2 - components/anchor_browser: {} + components/anchor_browser: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/annature: {} @@ -6660,8 +6664,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/kindo: - specifiers: {} + components/kindo: {} components/kingsumo: dependencies: @@ -7871,8 +7874,7 @@ importers: components/mindmeister: {} - components/mindstudio: - specifiers: {} + components/mindstudio: {} components/minio: {} @@ -12295,8 +12297,7 @@ importers: components/synthflow: {} - components/systeme_io: - specifiers: {} + components/systeme_io: {} components/t2m_url_shortener: {} @@ -34012,8 +34013,6 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) - transitivePeerDependencies: - - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: