diff --git a/components/appsflyer/actions/get-event-types/get-event-types.mjs b/components/appsflyer/actions/get-event-types/get-event-types.mjs new file mode 100644 index 0000000000000..1788632aa6cd7 --- /dev/null +++ b/components/appsflyer/actions/get-event-types/get-event-types.mjs @@ -0,0 +1,35 @@ +import app from "../../appsflyer.app.mjs"; + +export default { + key: "appsflyer-get-event-types", + name: "Get Event Types", + description: "Returns a list of the available event types for the specified endpoint type. [See the documentation](https://dev.appsflyer.com/hc/reference/get_event-types-attributing-entity)", + version: "0.0.1", + type: "action", + props: { + app, + attributingEntity: { + type: "string", + label: "Attributing Entity", + description: "The endpoint type.", + options: [ + "appsflyer", + "skadnetwork", + ], + }, + }, + async run({ $ }) { + const { + app, + attributingEntity, + } = this; + + const response = await app.getEventTypes({ + $, + attributingEntity, + }); + + $.export("$summary", `Successfully retrieved event types with request ID \`${response.request_id}\`.`); + return response; + }, +}; diff --git a/components/appsflyer/actions/get-message-fields/get-message-fields.mjs b/components/appsflyer/actions/get-message-fields/get-message-fields.mjs new file mode 100644 index 0000000000000..49f9dba968776 --- /dev/null +++ b/components/appsflyer/actions/get-message-fields/get-message-fields.mjs @@ -0,0 +1,36 @@ +import app from "../../appsflyer.app.mjs"; + +export default { + key: "appsflyer-get-message-fields", + name: "Get Message Fields", + description: "Returns a list of the available message fields for each platform. [See the documentation](https://dev.appsflyer.com/hc/reference/get_fields-platform)", + version: "0.0.1", + type: "action", + props: { + app, + platform: { + type: "string", + label: "Platform", + description: "The platform to retrieve message fields for.", + options: [ + "ios", + "android", + "windowsphone", + ], + }, + }, + async run({ $ }) { + const { + app, + platform, + } = this; + + const response = await app.getMessageFields({ + $, + platform, + }); + + $.export("$summary", `Successfully retrieved message fields with request ID \`${response.request_id}\`.`); + return response; + }, +}; diff --git a/components/appsflyer/appsflyer.app.mjs b/components/appsflyer/appsflyer.app.mjs index e61e956626312..366fdd2619af4 100644 --- a/components/appsflyer/appsflyer.app.mjs +++ b/components/appsflyer/appsflyer.app.mjs @@ -1,11 +1,99 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "appsflyer", - propDefinitions: {}, + propDefinitions: { + appId: { + type: "string", + label: "App ID", + description: "Your AppsFlyer App ID (e.g. `com.my.app`).", + async options() { + const { data } = await this.listApps(); + return data.map(({ + id: value, + attributes: { name: label }, + }) => ({ + label, + value, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path, baseUrl = constants.API.HQ1.BASE_URL) { + return `${baseUrl}${path}`; + }, + getHeaders() { + const { api_token: apiToken } = this.$auth; + return { + Authorization: `Bearer ${apiToken}`, + }; + }, + makeRequest({ + $ = this, path, baseUrl, ...args + } = {}) { + return axios($, { + ...args, + url: this.getUrl(path, baseUrl), + headers: this.getHeaders(), + }); + }, + post(args = {}) { + return this.makeRequest({ + method: "POST", + ...args, + }); + }, + put(args = {}) { + return this.makeRequest({ + method: "PUT", + ...args, + }); + }, + listApps(args = {}) { + return this.makeRequest({ + baseUrl: constants.API.HQ1.MNG_URL, + path: "/apps", + ...args, + }); + }, + getMessageFields({ + platform, ...args + } = {}) { + return this.makeRequest({ + baseUrl: constants.API.HQ1.PUSH_URL, + path: `/fields/${platform}`, + ...args, + }); + }, + getEventTypes({ + attributingEntity, ...args + } = {}) { + return this.makeRequest({ + baseUrl: constants.API.HQ1.PUSH_URL, + path: `/event-types/${attributingEntity}`, + ...args, + }); + }, + getPushApiConfiguration({ + appId, ...args + } = {}) { + return this.makeRequest({ + baseUrl: constants.API.HQ1.PUSH_URL, + path: `/app/${appId}`, + ...args, + }); + }, + updatePushApiConfiguration({ + appId, ...args + } = {}) { + return this.put({ + baseUrl: constants.API.HQ1.PUSH_URL, + path: `/app/${appId}`, + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/appsflyer/common/constants.mjs b/components/appsflyer/common/constants.mjs new file mode 100644 index 0000000000000..8211d1ad72802 --- /dev/null +++ b/components/appsflyer/common/constants.mjs @@ -0,0 +1,13 @@ +const HQ1_BASE_URL = "https://hq1.appsflyer.com"; + +const API = { + HQ1: { + BASE_URL: HQ1_BASE_URL, + PUSH_URL: `${HQ1_BASE_URL}/api/pushapi/v1.0`, + MNG_URL: `${HQ1_BASE_URL}/api/mng`, + }, +}; + +export default { + API, +}; diff --git a/components/appsflyer/package.json b/components/appsflyer/package.json index 39c46663b2b3d..f48241a5b3da3 100644 --- a/components/appsflyer/package.json +++ b/components/appsflyer/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/appsflyer", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream AppsFlyer Components", "main": "appsflyer.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/components/appsflyer/sources/common/webhook.mjs b/components/appsflyer/sources/common/webhook.mjs new file mode 100644 index 0000000000000..a05aa49d839e6 --- /dev/null +++ b/components/appsflyer/sources/common/webhook.mjs @@ -0,0 +1,87 @@ +import { ConfigurationError } from "@pipedream/platform"; +import app from "../../appsflyer.app.mjs"; + +export default { + props: { + app, + db: "$.service.db", + http: { + type: "$.interface.http", + customResponse: true, + }, + appId: { + propDefinition: [ + app, + "appId", + ], + }, + }, + hooks: { + async activate() { + const { + app, + appId, + http, + } = this; + const { endpoints = [] } = await app.getPushApiConfiguration({ + appId, + }); + + await app.updatePushApiConfiguration({ + appId, + data: { + endpoints: [ + ...endpoints, + { + method: "POST", + url: http.endpoint, + event_types: this.getEventTypes(), + attributing_entity: "appsflyer", + enabled: true, + }, + ], + }, + }); + }, + async deactivate() { + const { + app, + appId, + http, + } = this; + const { endpoints = [] } = await app.getPushApiConfiguration({ + appId, + }); + + await app.updatePushApiConfiguration({ + appId, + data: { + endpoints: endpoints.filter( + (endpoint) => endpoint.url !== http.endpoint, + ), + }, + }); + }, + }, + methods: { + generateMeta() { + throw new ConfigurationError("generateMeta is not implemented"); + }, + getEventTypes() { + throw new ConfigurationError("getEventTypes is not implemented"); + }, + processEvent(event) { + if (this.appId && event.app_id !== this.appId) { + return; + } + + this.$emit(event, this.generateMeta(event)); + }, + }, + async run({ body }) { + this.http.respond({ + status: 200, + }); + this.processEvent(body); + }, +}; diff --git a/components/appsflyer/sources/new-in-app-event-instant/new-in-app-event-instant.mjs b/components/appsflyer/sources/new-in-app-event-instant/new-in-app-event-instant.mjs new file mode 100644 index 0000000000000..d9001b2b03eed --- /dev/null +++ b/components/appsflyer/sources/new-in-app-event-instant/new-in-app-event-instant.mjs @@ -0,0 +1,29 @@ +import common from "../common/webhook.mjs"; + +export default { + ...common, + key: "appsflyer-new-in-app-event-instant", + name: "New In-App Event (Instant)", + description: "Emit new event when an in-app event is recorded, such as a purchase or level completion. [See docs here](https://dev.appsflyer.com/hc/reference/push-api-v2)", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEventTypes() { + return [ + "install-in-app-event", + "organic-install-in-app-event", + "re-engagement-in-app-event", + "re-attribution-in-app-event", + ]; + }, + generateMeta(event) { + return { + summary: `New In-App Event ${event.event_name}`, + id: event.event_id, + ts: Date.parse(event.event_time), + }; + }, + }, +}; diff --git a/components/appsflyer/sources/new-install-instant/new-install-instant.mjs b/components/appsflyer/sources/new-install-instant/new-install-instant.mjs new file mode 100644 index 0000000000000..68876097245bd --- /dev/null +++ b/components/appsflyer/sources/new-install-instant/new-install-instant.mjs @@ -0,0 +1,27 @@ +import common from "../common/webhook.mjs"; + +export default { + ...common, + key: "appsflyer-new-install-instant", + name: "New Install (Instant)", + description: "Emit new event when a user installs an app tracked by AppsFlyer. [See docs here](https://dev.appsflyer.com/hc/reference/push-api-v2)", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEventTypes() { + return [ + "install", + "organic-install", + ]; + }, + generateMeta(event) { + return { + summary: `New Install ${event.app_id}`, + id: event.event_id, + ts: Date.parse(event.event_time), + }; + }, + }, +}; diff --git a/components/appsflyer/sources/new-uninstall-instant/new-uninstall-instant.mjs b/components/appsflyer/sources/new-uninstall-instant/new-uninstall-instant.mjs new file mode 100644 index 0000000000000..18c47eb42c836 --- /dev/null +++ b/components/appsflyer/sources/new-uninstall-instant/new-uninstall-instant.mjs @@ -0,0 +1,26 @@ +import common from "../common/webhook.mjs"; + +export default { + ...common, + key: "appsflyer-new-uninstall-instant", + name: "New Uninstall (Instant)", + description: "Emit new event when a user uninstalls an app tracked by AppsFlyer. [See docs here](https://dev.appsflyer.com/hc/reference/push-api-v2)", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEventTypes() { + return [ + "uninstall", + ]; + }, + generateMeta(event) { + return { + summary: `New Uninstall ${event.app_id}`, + id: event.event_id, + ts: Date.parse(event.event_time), + }; + }, + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 714236346cff1..b1ce57bb5c5c0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -970,7 +970,11 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/appsflyer: {} + components/appsflyer: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/appveyor: dependencies: @@ -29624,22 +29628,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - deprecated: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731) + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net supports-color@2.0.0: resolution: {integrity: sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==} @@ -36617,8 +36621,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: