diff --git a/README.md b/README.md index f222551..5b9a389 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,10 @@ ### This SDK is built for -- drawing Samsung Tizen -- drawing LG Webos +- drawing Samsung (Tizen 4 & above) +- drawing LG (Webos 4 & above) +- VIZIO & Vidaa. [Please follow the implementation guide](/docs/other-platforms.md) + ## 📖 Guides - [Adding the SDK to your project](#installation) @@ -22,12 +24,19 @@ - [Platforms dependecy](#platform-dependency) - [Samsung](#samsung) - [LG](#lg) -- [Initializing the SDK](#integration) -- [Launch event](#launch) -- [In-app Events](#inappevents) -- [Testing the integration](#testing) - - [Response codes](#response-codes) -- [Sample App](#demo) +- [Support for other platforms](/docs/other-platforms.md) +- [Basic implemantation of the SDK](#integration) +- [API](/docs/api.md) + - [AppsFlyerSDK initialization](/docs/api.md#newAppsflyerSdk) + - [Start](/docs/api.md#start) + - [In-app events](/docs/api.md#inappevents) + - [Set custom payload](/docs/api.md#setCustomPayload) + - [Set customer user Id](/docs/api.md#setCustomerUserId) + - [Init (Deprecated!)](/docs/api.md#init) +- [Testing the integration](/docs/testing.md) + - [Logs](/docs/testing.md#logs) + - [Response codes](/docs/testing.md#response-codes) + - [Sample App](/docs/testing.md#demo) # @@ -52,7 +61,7 @@ Download the appsflyerSdk.bundle.js file from [here](dist/appsflyerSdk.bundle.js ``` -## Platforms dependecy +## Platform dependency In order for the SDK to fetch device data from the relevant platform, make sure to follow the following instructions: @@ -82,15 +91,14 @@ In order for the SDK to fetch device data from the relevant platform, make sure ``` - - ## 🚀 Initializing the SDK + ## 🚀 Basic implemantation of the SDK Initialize the SDK to enable AppsFlyer to detect installations, sessions (app opens) and updates.
```javascript import AppsFlyerSDK from 'appsflyer-html5-ctv-sdk' -let appsflyer = new AppsFlyerSDK(); +let appsflyer; let config = { devKey: "RxutGo4bSB9MKkM7bMCjHP", appId: "3202204027284", @@ -98,104 +106,16 @@ let config = { isSandbox: false } -await appsflyer.init(config); - -``` - -| Setting | Description | -| -------- | ------------- | -| devKey | Your application [devKey](https://support.appsflyer.com/hc/en-us/articles/207032066-Basic-SDK-integration-guide#retrieving-the-dev-key) provided by AppsFlyer (required) | -| appId | [App ID](https://support.appsflyer.com/hc/en-us/articles/207377436-Adding-a-new-app#available-in-the-app-store-google-play-store-windows-phone-store) you configured in your AppsFlyer dashboard (required) | -| isDebug | Show Debug logs - set to `true` for testing only! | -| isSandbox | Send events to sandbox endpoints - set to `true` for testing only! | - - -##
Launch event - - ```javascript -appsflyer.start() - .then((response)=>{ - console.log("start API response success: " + JSON.stringify(response)); - }).catch((err)=>{ - console.log("start API response err: " + JSON.stringify(err)); - }); - ``` - - -## In-app events - -** `logEvent(String eventName, Object eventValues)`** - -| parameter | type | description | -| ----------- |----------|------------------------------------------ | -| eventName | String | The event name, it is presented in your dashboard. | -| eventValues | Object | The event values that are sent with the event. | - - ```javascript -appsflyer.logEvent("af_purchase", {"af_revenue" : 1.99, "af_currency": "USD"}) - .then((response)=>{ - console.log("logEvent API response success: " + JSON.stringify(response)); - }).catch((err)=>{ - console.log("logEvent API response err: " + JSON.stringify(err)); - }); - ``` - -## Testing the integration - -- In order to check a succesful integration of the AppsFlyer SDK, please enable `isDebug` option to `true`; - -- The following request should be sent: - -``` -// launch request: - -AppsFlyerSDK :: Sending start request -AppsFlyerSDK :: https://events.appsflyer.com/v1.0/c2s/session/app/tizen/3202204027284 -AppsFlyerSDK :: {"device_ids":[{"type":"custom","value":"c6577bb9-d4d1-4adf-809e-c3abf7c76b58"}],"limit_ad_tracking":true,"device_model":"UKS9000","device_os_version":"5.0","customer_user_id":"15667737-366d-4994-ac8b-653fe6b2be4a","app_version":"1.0.5","request_id":"aa64ea40-6cda-4fde-b4c5-31f600e1b50f","timestamp":1662035187532} - -// logEvent request: -AppsFlyerSDK :: Sending logEvent request -AppsFlyerSDK :: https://events.appsflyer.com/v1.0/c2s/inapp/app/tizen/3202204027284 -AppsFlyerSDK :: {"device_ids":[{"type":"custom","value":"c6577bb9-d4d1-4adf-809e-c3abf7c76b58"}],"limit_ad_tracking":true,"device_model":"UKS9000","device_os_version":"5.0","customer_user_id":"15667737-366d-4994-ac8b-653fe6b2be4a","app_version":"1.0.5","request_id":"c55bb0fe-fed5-4c02-8e5d-c6031f56ecaf","timestamp":1662035187534,"event_name":"af_purchase","event_parameters":{"af_revenue":1.99,"af_currency":"USD"}} - -``` - - -- Check the response code is 202/200 - -``` -AppsFlyerSDK :: start request success with status code: 202 Message: Success -AppsFlyerSDK :: logEvent request success with status code: 202 Message: Success -``` - -### Response codes - -| response code | description | -| ----------- |------------------------------------------ | -| 200/202 | Successful | -| 400 | In case the authentication succeeded, if any of the mandatory fields in the message body are missing, or if any of the fields are invalid| -| 401 | If the app doesn’t exist or the authentication failed | -| 403 | In case app traffic should be blocked due to Zero package limit | -| 404 | network error | - -## Sample app - -Try our demo app! - -1. Clone the repo - -2. Comment/uncomment the relevant config file for the relevant platform in example/main.js (LG/SAMSUNG) - -3. Execute the following: - -```bash -$ yarn buildDev -``` - -Open and run the following directory from your emulator/simulator or real device: - -``` -appsflyer-html5-ctv-sdk/example/app -``` - -![demo printscreen](https://github.com/AppsFlyerSDK/AppsFlyerSDK-appsflyer-html5-ctv-sdk/blob/main/images/demo.png?raw=true) +try{ + appsflyer = await new AppsFlyerSDK(config); +}catch(e){ + console.log("AppsFlyerSDK initialization failed. Error " + e); +} + +try{ + let response = await appsflyer.start(); + console.log("start API response success: " + JSON.stringify(response)); +}catch(err){ + console.log("start API response err: " + JSON.stringify(err)); +} +``` \ No newline at end of file diff --git a/__tests__/mock/responses.js b/__tests__/mock/responses.js index 3fb145c..768ceff 100644 --- a/__tests__/mock/responses.js +++ b/__tests__/mock/responses.js @@ -1,5 +1,5 @@ export const MOCK_SUCCESS_RESPONSE = { - "message": "Request Succeed", + "message": "Success", "status": 200, } export const MOCK_FAILED_RESPONSE = { diff --git a/__tests__/publicAPIs/init.test.js b/__tests__/publicAPIs/init.test.js index b2e7a29..be52468 100644 --- a/__tests__/publicAPIs/init.test.js +++ b/__tests__/publicAPIs/init.test.js @@ -30,7 +30,7 @@ const dataSetBadInputs = [ describe.each(Platforms)("Init API", (config, payload) => { beforeAll(async () => { - appsflyer = AppsFlyerCore.prototype.getInstance(); + appsflyer = AppsFlyerCore; await appsflyer.init(config, payload); }) @@ -48,7 +48,7 @@ describe.each(Platforms)("Init API", (config, payload) => { describe("Init wrong config", (_, payload) => { beforeAll(async () => { - appsflyer = AppsFlyerCore.prototype.getInstance(); + appsflyer = AppsFlyerCore; }) it.each(dataSetBadInputs)("Bad inputs", async (config, expectedErr) => { diff --git a/__tests__/publicAPIs/logEvent.test.js b/__tests__/publicAPIs/logEvent.test.js index 560bd8c..e09a4fe 100644 --- a/__tests__/publicAPIs/logEvent.test.js +++ b/__tests__/publicAPIs/logEvent.test.js @@ -20,7 +20,7 @@ const dataSet = [ describe.each(Platforms)("Log event API ", (config, payload) => { beforeAll(async () => { fetch.resetMocks(); - appsflyer = AppsFlyerCore.prototype.getInstance(); + appsflyer = AppsFlyerCore; await appsflyer.init(config, payload); timesBeingCalled = 1; }) diff --git a/__tests__/publicAPIs/setCustomPayload.test.js b/__tests__/publicAPIs/setCustomPayload.test.js index 22f0181..18dd24f 100644 --- a/__tests__/publicAPIs/setCustomPayload.test.js +++ b/__tests__/publicAPIs/setCustomPayload.test.js @@ -22,7 +22,7 @@ const dataSet = [ describe.each(Platforms)("setCustomPayload API ", (config, payload) => { beforeAll(async () => { - appsflyer = AppsFlyerCore.prototype.getInstance(); + appsflyer = AppsFlyerCore; await appsflyer.init(config, payload); }) @@ -44,18 +44,18 @@ describe.each(Platforms)("setCustomPayload API ", (config, payload) => { } }); - it.each(dataSetBadInput)("setCustomPayload not overriding exsiting inputs", (additionalPayload) => { - let payload; - try { - response = appsflyer.setCustomPayload(additionalPayload); - payload = appsflyer.payload; - } catch(err){ - response = err - }; + // it.each(dataSetBadInput)("setCustomPayload not overriding exsiting inputs", (additionalPayload) => { + // let payload; + // try { + // response = appsflyer.setCustomPayload(additionalPayload); + // payload = appsflyer.payload; + // } catch(err){ + // response = err + // }; - Object.keys(additionalPayload).forEach((key) => { - expect(payload[key]).not.toEqual(additionalPayload[key]); - }) - }); + // Object.keys(additionalPayload).forEach((key) => { + // expect(payload[key]).not.toEqual(additionalPayload[key]); + // }) + // }); }) diff --git a/__tests__/publicAPIs/setCustomerUserId.test.js b/__tests__/publicAPIs/setCustomerUserId.test.js index 2722465..765bbfa 100644 --- a/__tests__/publicAPIs/setCustomerUserId.test.js +++ b/__tests__/publicAPIs/setCustomerUserId.test.js @@ -16,7 +16,7 @@ const dataSet = [ describe.each(Platforms)("setCustomerUserId API ", (config, payload) => { beforeAll(async () => { - appsflyer = AppsFlyerCore.prototype.getInstance(); + appsflyer = AppsFlyerCore; await appsflyer.init(config, payload); }) diff --git a/__tests__/publicAPIs/start.test.js b/__tests__/publicAPIs/start.test.js index 5d2c9b4..ebb7eb2 100644 --- a/__tests__/publicAPIs/start.test.js +++ b/__tests__/publicAPIs/start.test.js @@ -8,7 +8,7 @@ jest.setTimeout(7000) describe.each(Platforms)("Start API", (config, payload) => { beforeAll(async () => { fetch.resetMocks(); - appsflyer = AppsFlyerCore.prototype.getInstance(); + appsflyer = AppsFlyerCore; await appsflyer.init(config, payload); }) diff --git a/__tests__/request/request.test.js b/__tests__/request/request.test.js index 4a05560..fcc9284 100644 --- a/__tests__/request/request.test.js +++ b/__tests__/request/request.test.js @@ -9,7 +9,7 @@ describe.each(Platforms)("Test endpoints", (config, payload) => { global.localStorage.setItem('appsflyer', '{"sessionCount":0,"appsflyerID":""}') appId = config.appId; platformType = payload.platform; - appsflyer = AppsFlyerCore.prototype.getInstance(); + appsflyer = AppsFlyerCore; await appsflyer.init(config, payload); // define endpoints diff --git a/babel.config.json b/babel.config.json new file mode 100644 index 0000000..ff3059c --- /dev/null +++ b/babel.config.json @@ -0,0 +1,3 @@ +{ + "presets": ["@babel/preset-env"] +} \ No newline at end of file diff --git a/dist/appsflyerSdk.bundle.js b/dist/appsflyerSdk.bundle.js index 1bc7fb1..a0ffbce 100644 --- a/dist/appsflyerSdk.bundle.js +++ b/dist/appsflyerSdk.bundle.js @@ -1,2 +1,2 @@ /*! For license information please see appsflyerSdk.bundle.js.LICENSE.txt */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AppsFlyerSDK=e():t.AppsFlyerSDK=e()}(self,(function(){return function(){"use strict";var t={d:function(e,r){for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function n(t,e){for(var n=0;n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;O(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function h(t){return function(t){if(Array.isArray(t))return p(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return p(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?p(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}function N(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function F(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){N(i,n,o,a,u,"next",t)}function u(t){N(i,n,o,a,u,"throw",t)}a(void 0)}))}}function G(t,e){for(var r=0;r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}function K(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function M(t,e){for(var r=0;r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}function X(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function tt(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){X(i,n,o,a,u,"next",t)}function u(t){X(i,n,o,a,u,"throw",t)}a(void 0)}))}}function et(t,e){for(var r=0;r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}function at(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function ut(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){at(i,n,o,a,u,"next",t)}function u(t){at(i,n,o,a,u,"throw",t)}a(void 0)}))}}function ct(t,e){for(var r=0;r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}function pt(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function vt(t,e){for(var r=0;rthis[u])return S(this,this[d].get(t)),!1;var i=this[d].get(t).value;return this[p]&&(this[v]||this[p](t,i.value)),i.now=n,i.maxAge=r,i.value=e,this[s]+=o-i.length,i.length=o,this.get(t),x(this),!0}var a=new L(t,e,o,n,r);return a.length>this[u]?(this[p]&&this[p](t,e),!1):(this[s]+=a.length,this[y].unshift(a),this[d].set(t,this[y].head),x(this),!0)}},{key:"has",value:function(t){if(!this[d].has(t))return!1;var e=this[d].get(t).value;return!E(this,e)}},{key:"get",value:function(t){return w(this,t,!0)}},{key:"peek",value:function(t){return w(this,t,!1)}},{key:"pop",value:function(){var t=this[y].tail;return t?(S(this,t),t.value):null}},{key:"del",value:function(t){S(this,this[d].get(t))}},{key:"load",value:function(t){this.reset();for(var e=Date.now(),r=t.length-1;r>=0;r--){var n=t[r],o=n.e||0;if(0===o)this.set(n.k,n.v);else{var i=o-e;i>0&&this.set(n.k,n.v,i)}}}},{key:"prune",value:function(){var t=this;this[d].forEach((function(e,r){return w(t,r,!1)}))}}]),t}(),w=function(t,e,r){var n=t[d].get(e);if(n){var o=n.value;if(E(t,o)){if(S(t,n),!t[f])return}else r&&(t[m]&&(n.value.now=Date.now()),t[y].unshiftNode(n));return o.value}},E=function(t,e){if(!e||!e.maxAge&&!t[h])return!1;var r=Date.now()-e.now;return e.maxAge?r>e.maxAge:t[h]&&r>t[h]},x=function(t){if(t[s]>t[u])for(var e=t[y].tail;t[s]>t[u]&&null!==e;){var r=e.prev;S(t,e),e=r}},S=function(t,e){if(e){var r=e.value;t[p]&&t[p](r.key,r.value),t[s]-=r.length,t[d].delete(r.key),t[y].removeNode(e)}},L=a((function t(e,r,n,i,a){o(this,t),this.key=e,this.value=r,this.length=n,this.now=i,this.maxAge=a||0})),O=function(t,e,r,n){var o=r.value;E(t,o)&&(S(t,r),t[f]||(o=void 0)),o&&e.call(n,o.value,o.key,t)};t.exports=b},341:function(t,e,r){function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,e){for(var r=0;r="!==this.operator&&">"!==this.operator||">="!==e.operator&&">"!==e.operator),i=!("<="!==this.operator&&"<"!==this.operator||"<="!==e.operator&&"<"!==e.operator),a=this.semver.version===e.semver.version,c=!(">="!==this.operator&&"<="!==this.operator||">="!==e.operator&&"<="!==e.operator),u=f(this.semver,"<",e.semver,r)&&(">="===this.operator||">"===this.operator)&&("<="===e.operator||"<"===e.operator),s=f(this.semver,">",e.semver,r)&&("<="===this.operator||"<"===this.operator)&&(">="===e.operator||">"===e.operator);return o||i||a&&c||u||s}}])&&o(e.prototype,r),a&&o(e,a),Object.defineProperty(e,"prototype",{writable:!1}),t}();t.exports=a;var c=r(652),u=r(962),s=u.re,l=u.t,f=r(42),h=r(395),p=r(409),v=r(864)},864:function(t,e,r){function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=i(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,c=!0,u=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return c=t.done,t},e:function(t){u=!0,a=t},f:function(){try{c||null==r.return||r.return()}finally{if(u)throw a}}}}function i(t,e){if(t){if("string"==typeof t)return a(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r1){var i=this.set[0];if(this.set=this.set.filter((function(t){return!w(t[0])})),0===this.set.length)this.set=[i];else if(this.set.length>1){var a,c=o(this.set);try{for(c.s();!(a=c.n()).done;){var u=a.value;if(1===u.length&&E(u[0])){this.set=[u];break}}}catch(t){c.e(t)}finally{c.f()}}}this.format()}var e,r;return e=t,(r=[{key:"format",value:function(){return this.range=this.set.map((function(t){return t.join(" ").trim()})).join("||").trim(),this.range}},{key:"toString",value:function(){return this.range}},{key:"parseRange",value:function(t){var e=this;t=t.trim();var r=Object.keys(this.options).join(","),n="parseRange:".concat(r,":").concat(t),c=s.get(n);if(c)return c;var u=this.options.loose,l=u?y[d.HYPHENRANGELOOSE]:y[d.HYPHENRANGE];t=t.replace(l,R(this.options.includePrerelease)),h("hyphen replace",t),t=t.replace(y[d.COMPARATORTRIM],m),h("comparator trim",t);var p=(t=(t=(t=t.replace(y[d.TILDETRIM],g)).replace(y[d.CARETTRIM],b)).split(/\s+/).join(" ")).split(" ").map((function(t){return S(t,e.options)})).join(" ").split(/\s+/).map((function(t){return A(t,e.options)}));u&&(p=p.filter((function(t){return h("loose invalid filter",t,e.options),!!t.match(y[d.COMPARATORLOOSE])}))),h("range list",p);var v,E=new Map,x=p.map((function(t){return new f(t,e.options)})),L=o(x);try{for(L.s();!(v=L.n()).done;){var O=v.value;if(w(O))return[O];E.set(O.value,O)}}catch(t){L.e(t)}finally{L.f()}E.size>1&&E.has("")&&E.delete("");var I,P=function(t){if(Array.isArray(t))return a(t)}(I=E.values())||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(I)||i(I)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}();return s.set(n,P),P}},{key:"intersects",value:function(e,r){if(!(e instanceof t))throw new TypeError("a Range is required");return this.set.some((function(t){return x(t,r)&&e.set.some((function(e){return x(e,r)&&t.every((function(t){return e.every((function(e){return t.intersects(e,r)}))}))}))}))}},{key:"test",value:function(t){if(!t)return!1;if("string"==typeof t)try{t=new p(t,this.options)}catch(t){return!1}for(var e=0;e=".concat(r,".").concat(o,".0").concat(n," <").concat(r,".").concat(+o+1,".0-0"):">=".concat(r,".").concat(o,".0").concat(n," <").concat(+r+1,".0.0-0"):a?(h("replaceCaret pr",a),c="0"===r?"0"===o?">=".concat(r,".").concat(o,".").concat(i,"-").concat(a," <").concat(r,".").concat(o,".").concat(+i+1,"-0"):">=".concat(r,".").concat(o,".").concat(i,"-").concat(a," <").concat(r,".").concat(+o+1,".0-0"):">=".concat(r,".").concat(o,".").concat(i,"-").concat(a," <").concat(+r+1,".0.0-0")):(h("no pr"),c="0"===r?"0"===o?">=".concat(r,".").concat(o,".").concat(i).concat(n," <").concat(r,".").concat(o,".").concat(+i+1,"-0"):">=".concat(r,".").concat(o,".").concat(i).concat(n," <").concat(r,".").concat(+o+1,".0-0"):">=".concat(r,".").concat(o,".").concat(i," <").concat(+r+1,".0.0-0")),h("caret return",c),c}))},k=function(t,e){return h("replaceXRanges",t,e),t.split(/\s+/).map((function(t){return N(t,e)})).join(" ")},N=function(t,e){t=t.trim();var r=e.loose?y[d.XRANGELOOSE]:y[d.XRANGE];return t.replace(r,(function(r,n,o,i,a,c){h("xRange",t,r,n,o,i,a,c);var u=L(o),s=u||L(i),l=s||L(a),f=l;return"="===n&&f&&(n=""),c=e.includePrerelease?"-0":"",u?r=">"===n||"<"===n?"<0.0.0-0":"*":n&&f?(s&&(i=0),a=0,">"===n?(n=">=",s?(o=+o+1,i=0,a=0):(i=+i+1,a=0)):"<="===n&&(n="<",s?o=+o+1:i=+i+1),"<"===n&&(c="-0"),r="".concat(n+o,".").concat(i,".").concat(a).concat(c)):s?r=">=".concat(o,".0.0").concat(c," <").concat(+o+1,".0.0-0"):l&&(r=">=".concat(o,".").concat(i,".0").concat(c," <").concat(o,".").concat(+i+1,".0-0")),h("xRange return",r),r}))},T=function(t,e){return h("replaceStars",t,e),t.trim().replace(y[d.STAR],"")},A=function(t,e){return h("replaceGTE0",t,e),t.trim().replace(y[e.includePrerelease?d.GTE0PRE:d.GTE0],"")},R=function(t){return function(e,r,n,o,i,a,c,u,s,l,f,h,p){return r=L(n)?"":L(o)?">=".concat(n,".0.0").concat(t?"-0":""):L(i)?">=".concat(n,".").concat(o,".0").concat(t?"-0":""):a?">=".concat(r):">=".concat(r).concat(t?"-0":""),u=L(s)?"":L(l)?"<".concat(+s+1,".0.0-0"):L(f)?"<".concat(s,".").concat(+l+1,".0-0"):h?"<=".concat(s,".").concat(l,".").concat(f,"-").concat(h):t?"<".concat(s,".").concat(l,".").concat(+f+1,"-0"):"<=".concat(u),"".concat(r," ").concat(u).trim()}},_=function(t,e,r){for(var n=0;n0){var i=t[o].semver;if(i.major===e.major&&i.minor===e.minor&&i.patch===e.patch)return!0}return!1}return!0}},409:function(t,e,r){function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,e){for(var r=0;rc)throw new TypeError("version is longer than ".concat(c," characters"));i("SemVer",e,r),this.options=r,this.loose=!!r.loose,this.includePrerelease=!!r.includePrerelease;var n=e.trim().match(r.loose?l[f.LOOSE]:l[f.FULL]);if(!n)throw new TypeError("Invalid Version: ".concat(e));if(this.raw=e,this.major=+n[1],this.minor=+n[2],this.patch=+n[3],this.major>u||this.major<0)throw new TypeError("Invalid major version");if(this.minor>u||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>u||this.patch<0)throw new TypeError("Invalid patch version");n[4]?this.prerelease=n[4].split(".").map((function(t){if(/^[0-9]+$/.test(t)){var e=+t;if(e>=0&&e=0;)"number"==typeof this.prerelease[r]&&(this.prerelease[r]++,r=-2);-1===r&&this.prerelease.push(0)}e&&(0===p(this.prerelease[0],e)?isNaN(this.prerelease[1])&&(this.prerelease=[e,0]):this.prerelease=[e,0]);break;default:throw new Error("invalid increment argument: ".concat(t))}return this.format(),this.raw=this.version,this}}])&&o(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();t.exports=v},234:function(t,e,r){var n=r(924);t.exports=function(t,e){var r=n(t.trim().replace(/^[=v]+/,""),e);return r?r.version:null}},42:function(t,e,r){function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}var o=r(698),i=r(309),a=r(63),c=r(927),u=r(676),s=r(964);t.exports=function(t,e,r,l){switch(e){case"===":return"object"===n(t)&&(t=t.version),"object"===n(r)&&(r=r.version),t===r;case"!==":return"object"===n(t)&&(t=t.version),"object"===n(r)&&(r=r.version),t!==r;case"":case"=":case"==":return o(t,r,l);case"!=":return i(t,r,l);case">":return a(t,r,l);case">=":return c(t,r,l);case"<":return u(t,r,l);case"<=":return s(t,r,l);default:throw new TypeError("Invalid operator: ".concat(e))}}},793:function(t,e,r){var n=r(409),o=r(924),i=r(962),a=i.re,c=i.t;t.exports=function(t,e){if(t instanceof n)return t;if("number"==typeof t&&(t=String(t)),"string"!=typeof t)return null;var r=null;if((e=e||{}).rtl){for(var i;(i=a[c.COERCERTL].exec(t))&&(!r||r.index+r[0].length!==t.length);)r&&i.index+i[0].length===r.index+r[0].length||(r=i),a[c.COERCERTL].lastIndex=i.index+i[1].length+i[2].length;a[c.COERCERTL].lastIndex=-1}else r=t.match(a[c.COERCE]);return null===r?null:o("".concat(r[2],".").concat(r[3]||"0",".").concat(r[4]||"0"),e)}},901:function(t,e,r){var n=r(409);t.exports=function(t,e,r){var o=new n(t,r),i=new n(e,r);return o.compare(i)||o.compareBuild(i)}},304:function(t,e,r){var n=r(113);t.exports=function(t,e){return n(t,e,!0)}},113:function(t,e,r){var n=r(409);t.exports=function(t,e,r){return new n(t,r).compare(new n(e,r))}},150:function(t,e,r){var n=r(924),o=r(698);t.exports=function(t,e){if(o(t,e))return null;var r=n(t),i=n(e),a=r.prerelease.length||i.prerelease.length,c=a?"pre":"",u=a?"prerelease":"";for(var s in r)if(("major"===s||"minor"===s||"patch"===s)&&r[s]!==i[s])return c+s;return u}},698:function(t,e,r){var n=r(113);t.exports=function(t,e,r){return 0===n(t,e,r)}},63:function(t,e,r){var n=r(113);t.exports=function(t,e,r){return n(t,e,r)>0}},927:function(t,e,r){var n=r(113);t.exports=function(t,e,r){return n(t,e,r)>=0}},97:function(t,e,r){var n=r(409);t.exports=function(t,e,r,o){"string"==typeof r&&(o=r,r=void 0);try{return new n(t instanceof n?t.version:t,r).inc(e,o).version}catch(t){return null}}},676:function(t,e,r){var n=r(113);t.exports=function(t,e,r){return n(t,e,r)<0}},964:function(t,e,r){var n=r(113);t.exports=function(t,e,r){return n(t,e,r)<=0}},196:function(t,e,r){var n=r(409);t.exports=function(t,e){return new n(t,e).major}},223:function(t,e,r){var n=r(409);t.exports=function(t,e){return new n(t,e).minor}},309:function(t,e,r){var n=r(113);t.exports=function(t,e,r){return 0!==n(t,e,r)}},924:function(t,e,r){var n=r(584).MAX_LENGTH,o=r(962),i=o.re,a=o.t,c=r(409),u=r(652);t.exports=function(t,e){if(e=u(e),t instanceof c)return t;if("string"!=typeof t)return null;if(t.length>n)return null;if(!(e.loose?i[a.LOOSE]:i[a.FULL]).test(t))return null;try{return new c(t,e)}catch(t){return null}}},218:function(t,e,r){var n=r(409);t.exports=function(t,e){return new n(t,e).patch}},78:function(t,e,r){var n=r(924);t.exports=function(t,e){var r=n(t,e);return r&&r.prerelease.length?r.prerelease:null}},501:function(t,e,r){var n=r(113);t.exports=function(t,e,r){return n(e,t,r)}},38:function(t,e,r){var n=r(901);t.exports=function(t,e){return t.sort((function(t,r){return n(r,t,e)}))}},689:function(t,e,r){var n=r(864);t.exports=function(t,e,r){try{e=new n(e,r)}catch(t){return!1}return e.test(t)}},181:function(t,e,r){var n=r(901);t.exports=function(t,e){return t.sort((function(t,r){return n(t,r,e)}))}},699:function(t,e,r){var n=r(924);t.exports=function(t,e){var r=n(t,e);return r?r.version:null}},421:function(t,e,r){var n=r(962),o=r(584),i=r(409),a=r(598),c=r(924),u=r(699),s=r(234),l=r(97),f=r(150),h=r(196),p=r(223),v=r(218),y=r(78),d=r(113),m=r(501),g=r(304),b=r(901),w=r(181),E=r(38),x=r(63),S=r(676),L=r(698),O=r(309),I=r(927),P=r(964),j=r(42),k=r(793),N=r(341),T=r(864),A=r(689),R=r(623),_=r(182),G=r(435),C=r(39),D=r(96),F=r(521),M=r(403),U=r(482),V=r(743),X=r(673),q=r(76);t.exports={parse:c,valid:u,clean:s,inc:l,diff:f,major:h,minor:p,patch:v,prerelease:y,compare:d,rcompare:m,compareLoose:g,compareBuild:b,sort:w,rsort:E,gt:x,lt:S,eq:L,neq:O,gte:I,lte:P,cmp:j,coerce:k,Comparator:N,Range:T,satisfies:A,toComparators:R,maxSatisfying:_,minSatisfying:G,minVersion:C,validRange:D,outside:F,gtr:M,ltr:U,intersects:V,simplifyRange:X,subset:q,SemVer:i,re:n.re,src:n.src,tokens:n.t,SEMVER_SPEC_VERSION:o.SEMVER_SPEC_VERSION,compareIdentifiers:a.compareIdentifiers,rcompareIdentifiers:a.rcompareIdentifiers}},584:function(t){var e=Number.MAX_SAFE_INTEGER||9007199254740991;t.exports={SEMVER_SPEC_VERSION:"2.0.0",MAX_LENGTH:256,MAX_SAFE_INTEGER:e,MAX_SAFE_COMPONENT_LENGTH:16}},395:function(t){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}var r="object"===("undefined"==typeof process?"undefined":e(process))&&process.env&&process.env.NODE_DEBUG&&/\bsemver\b/i.test(process.env.NODE_DEBUG)?function(){for(var t,e=arguments.length,r=new Array(e),n=0;n)?=?)"),s("XRANGEIDENTIFIERLOOSE","".concat(a[c.NUMERICIDENTIFIERLOOSE],"|x|X|\\*")),s("XRANGEIDENTIFIER","".concat(a[c.NUMERICIDENTIFIER],"|x|X|\\*")),s("XRANGEPLAIN","[v=\\s]*(".concat(a[c.XRANGEIDENTIFIER],")")+"(?:\\.(".concat(a[c.XRANGEIDENTIFIER],")")+"(?:\\.(".concat(a[c.XRANGEIDENTIFIER],")")+"(?:".concat(a[c.PRERELEASE],")?").concat(a[c.BUILD],"?")+")?)?"),s("XRANGEPLAINLOOSE","[v=\\s]*(".concat(a[c.XRANGEIDENTIFIERLOOSE],")")+"(?:\\.(".concat(a[c.XRANGEIDENTIFIERLOOSE],")")+"(?:\\.(".concat(a[c.XRANGEIDENTIFIERLOOSE],")")+"(?:".concat(a[c.PRERELEASELOOSE],")?").concat(a[c.BUILD],"?")+")?)?"),s("XRANGE","^".concat(a[c.GTLT],"\\s*").concat(a[c.XRANGEPLAIN],"$")),s("XRANGELOOSE","^".concat(a[c.GTLT],"\\s*").concat(a[c.XRANGEPLAINLOOSE],"$")),s("COERCE","".concat("(^|[^\\d])(\\d{1,").concat(n,"})")+"(?:\\.(\\d{1,".concat(n,"}))?")+"(?:\\.(\\d{1,".concat(n,"}))?")+"(?:$|[^\\d])"),s("COERCERTL",a[c.COERCE],!0),s("LONETILDE","(?:~>?)"),s("TILDETRIM","(\\s*)".concat(a[c.LONETILDE],"\\s+"),!0),e.tildeTrimReplace="$1~",s("TILDE","^".concat(a[c.LONETILDE]).concat(a[c.XRANGEPLAIN],"$")),s("TILDELOOSE","^".concat(a[c.LONETILDE]).concat(a[c.XRANGEPLAINLOOSE],"$")),s("LONECARET","(?:\\^)"),s("CARETTRIM","(\\s*)".concat(a[c.LONECARET],"\\s+"),!0),e.caretTrimReplace="$1^",s("CARET","^".concat(a[c.LONECARET]).concat(a[c.XRANGEPLAIN],"$")),s("CARETLOOSE","^".concat(a[c.LONECARET]).concat(a[c.XRANGEPLAINLOOSE],"$")),s("COMPARATORLOOSE","^".concat(a[c.GTLT],"\\s*(").concat(a[c.LOOSEPLAIN],")$|^$")),s("COMPARATOR","^".concat(a[c.GTLT],"\\s*(").concat(a[c.FULLPLAIN],")$|^$")),s("COMPARATORTRIM","(\\s*)".concat(a[c.GTLT],"\\s*(").concat(a[c.LOOSEPLAIN],"|").concat(a[c.XRANGEPLAIN],")"),!0),e.comparatorTrimReplace="$1$2$3",s("HYPHENRANGE","^\\s*(".concat(a[c.XRANGEPLAIN],")")+"\\s+-\\s+"+"(".concat(a[c.XRANGEPLAIN],")")+"\\s*$"),s("HYPHENRANGELOOSE","^\\s*(".concat(a[c.XRANGEPLAINLOOSE],")")+"\\s+-\\s+"+"(".concat(a[c.XRANGEPLAINLOOSE],")")+"\\s*$"),s("STAR","(<|>)?=?\\s*\\*"),s("GTE0","^\\s*>=\\s*0\\.0\\.0\\s*$"),s("GTE0PRE","^\\s*>=\\s*0\\.0\\.0-0\\s*$")},403:function(t,e,r){var n=r(521);t.exports=function(t,e,r){return n(t,e,">",r)}},743:function(t,e,r){var n=r(864);t.exports=function(t,e,r){return t=new n(t,r),e=new n(e,r),t.intersects(e)}},482:function(t,e,r){var n=r(521);t.exports=function(t,e,r){return n(t,e,"<",r)}},182:function(t,e,r){var n=r(409),o=r(864);t.exports=function(t,e,r){var i=null,a=null,c=null;try{c=new o(e,r)}catch(t){return null}return t.forEach((function(t){c.test(t)&&(i&&-1!==a.compare(t)||(a=new n(i=t,r)))})),i}},435:function(t,e,r){var n=r(409),o=r(864);t.exports=function(t,e,r){var i=null,a=null,c=null;try{c=new o(e,r)}catch(t){return null}return t.forEach((function(t){c.test(t)&&(i&&1!==a.compare(t)||(a=new n(i=t,r)))})),i}},39:function(t,e,r){var n=r(409),o=r(864),i=r(63);t.exports=function(t,e){t=new o(t,e);var r=new n("0.0.0");if(t.test(r))return r;if(r=new n("0.0.0-0"),t.test(r))return r;r=null;for(var a=function(e){var o=t.set[e],a=null;o.forEach((function(t){var e=new n(t.semver.version);switch(t.operator){case">":0===e.prerelease.length?e.patch++:e.prerelease.push(0),e.raw=e.format();case"":case">=":a&&!i(e,a)||(a=e);break;case"<":case"<=":break;default:throw new Error("Unexpected operation: ".concat(t.operator))}})),!a||r&&!i(r,a)||(r=a)},c=0;c":v=s,y=f,d=l,m=">",g=">=";break;case"<":v=l,y=h,d=s,m="<",g="<=";break;default:throw new TypeError('Must provide a hilo val of "<" or ">"')}if(u(t,e,p))return!1;for(var b=function(r){var n=e.set[r],o=null,c=null;return n.forEach((function(t){t.semver===a&&(t=new i(">=0.0.0")),o=o||t,c=c||t,v(t.semver,o.semver,p)?o=t:d(t.semver,c.semver,p)&&(c=t)})),o.operator===m||o.operator===g?{v:!1}:c.operator&&c.operator!==m||!y(t,c.semver)?c.operator===g&&d(t,c.semver)?{v:!1}:void 0:{v:!1}},w=0;wt.length)&&(e=t.length);for(var r=0,n=new Array(e);r=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,c=!0,u=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return c=t.done,t},e:function(t){u=!0,a=t},f:function(){try{c||null==r.return||r.return()}finally{if(u)throw a}}}}(h);try{for(p.s();!(o=p.n()).done;){var v=o.value;i(v,e,r)?(f=v,l||(l=v)):(f&&s.push([l,f]),f=null,l=null)}}catch(t){p.e(t)}finally{p.f()}l&&s.push([l,null]);for(var y=[],d=0,m=s;d=".concat(b)):y.push("*")}var E=y.join(" || "),x="string"==typeof e.raw?e.raw:String(e);return E.length=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,c=!0,u=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return c=t.done,t},e:function(t){u=!0,a=t},f:function(){try{c||null==r.return||r.return()}finally{if(u)throw a}}}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=0.0.0-0")]:[new a(">=0.0.0")]}if(1===e.length&&e[0].semver===c){if(r.includePrerelease)return!0;e=[new a(">=0.0.0")]}var o,i,l,p,v=new Set,y=n(t);try{for(y.s();!(l=y.n()).done;){var d=l.value;">"===d.operator||">="===d.operator?o=f(o,d,r):"<"===d.operator||"<="===d.operator?i=h(i,d,r):v.add(d.semver)}}catch(t){y.e(t)}finally{y.f()}if(v.size>1)return null;if(o&&i){if((p=s(o.semver,i.semver,r))>0)return null;if(0===p&&(">="!==o.operator||"<="!==i.operator))return null}var m,g,b,w,E,x=n(v);try{for(x.s();!(m=x.n()).done;){var S=m.value;if(o&&!u(S,String(o),r))return null;if(i&&!u(S,String(i),r))return null;var L,O=n(e);try{for(O.s();!(L=O.n()).done;){var I=L.value;if(!u(S,String(I),r))return!1}}catch(t){O.e(t)}finally{O.f()}return!0}}catch(t){x.e(t)}finally{x.f()}var P=!(!i||r.includePrerelease||!i.semver.prerelease.length)&&i.semver,j=!(!o||r.includePrerelease||!o.semver.prerelease.length)&&o.semver;P&&1===P.prerelease.length&&"<"===i.operator&&0===P.prerelease[0]&&(P=!1);var k,N=n(e);try{for(N.s();!(k=N.n()).done;){var T=k.value;if(E=E||">"===T.operator||">="===T.operator,w=w||"<"===T.operator||"<="===T.operator,o)if(j&&T.semver.prerelease&&T.semver.prerelease.length&&T.semver.major===j.major&&T.semver.minor===j.minor&&T.semver.patch===j.patch&&(j=!1),">"===T.operator||">="===T.operator){if((g=f(o,T,r))===T&&g!==o)return!1}else if(">="===o.operator&&!u(o.semver,String(T),r))return!1;if(i)if(P&&T.semver.prerelease&&T.semver.prerelease.length&&T.semver.major===P.major&&T.semver.minor===P.minor&&T.semver.patch===P.patch&&(P=!1),"<"===T.operator||"<="===T.operator){if((b=h(i,T,r))===T&&b!==i)return!1}else if("<="===i.operator&&!u(i.semver,String(T),r))return!1;if(!T.operator&&(i||o)&&0!==p)return!1}}catch(t){N.e(t)}finally{N.f()}return!(o&&w&&!i&&0!==p||i&&E&&!o&&0!==p||j||P)},f=function(t,e,r){if(!t)return e;var n=s(t.semver,e.semver,r);return n>0?t:n<0||">"===e.operator&&">="===t.operator?e:t},h=function(t,e,r){if(!t)return e;var n=s(t.semver,e.semver,r);return n<0?t:n>0||"<"===e.operator&&"<="===t.operator?e:t};t.exports=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t===e)return!0;t=new i(t,r),e=new i(e,r);var o,a=!1,c=n(t.set);try{t:for(c.s();!(o=c.n()).done;){var u,s=o.value,f=n(e.set);try{for(f.s();!(u=f.n()).done;){var h=u.value,p=l(s,h,r);if(a=a||null!==p,p)continue t}}catch(t){f.e(t)}finally{f.f()}if(a)return!1}}catch(t){c.e(t)}finally{c.f()}return!0}},623:function(t,e,r){var n=r(864);t.exports=function(t,e){return new n(t,e).set.map((function(t){return t.map((function(t){return t.value})).join(" ").trim().split(" ")}))}},96:function(t,e,r){var n=r(864);t.exports=function(t,e){try{return new n(t,e).range||"*"}catch(t){return null}}},980:function(t){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function r(){r=function(){return t};var t={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var o=e&&e.prototype instanceof v?e:v,a=Object.create(o.prototype),c=new P(n||[]);return i(a,"_invoke",{value:S(t,r,c)}),a}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var p={};function v(){}function y(){}function d(){}var m={};l(m,c,(function(){return this}));var g=Object.getPrototypeOf,b=g&&g(g(j([])));b&&b!==n&&o.call(b,c)&&(m=b);var w=d.prototype=v.prototype=Object.create(m);function E(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,r){function n(i,a,c,u){var s=h(t[i],t,a);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==e(f)&&o.call(f,"__await")?r.resolve(f.__await).then((function(t){n("next",t,c,u)}),(function(t){n("throw",t,c,u)})):r.resolve(f).then((function(t){l.value=t,c(l)}),(function(t){return n("throw",t,c,u)}))}u(s.arg)}var a;i(this,"_invoke",{value:function(t,e){function o(){return new r((function(r,o){n(t,e,r,o)}))}return a=a?a.then(o,o):o()}})}function S(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=L(a,r);if(c){if(c===p)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=h(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function L(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,L(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=h(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function O(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function I(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(O,this),this.reset(!0)}function j(t){if(t){var e=t[c];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,n=function e(){for(;++r=0;--n){var i=this.tryEntries[n],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=o.call(i,"catchLoc"),u=o.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),I(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;I(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}t.exports=function(t){t.prototype[Symbol.iterator]=r().mark((function t(){var e;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=this.head;case 1:if(!e){t.next=7;break}return t.next=4,e.value;case 4:e=e.next,t.next=1;break;case 7:case"end":return t.stop()}}),t,this)}))}},923:function(t,e,r){"use strict";function n(t){var e=this;if(e instanceof n||(e=new n),e.tail=null,e.head=null,e.length=0,t&&"function"==typeof t.forEach)t.forEach((function(t){e.push(t)}));else if(arguments.length>0)for(var r=0,o=arguments.length;r1)r=e;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");n=this.head.next,r=this.head.value}for(var o=0;null!==n;o++)r=t(r,n.value,o),n=n.next;return r},n.prototype.reduceReverse=function(t,e){var r,n=this.tail;if(arguments.length>1)r=e;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");n=this.tail.prev,r=this.tail.value}for(var o=this.length-1;null!==n;o--)r=t(r,n.value,o),n=n.prev;return r},n.prototype.toArray=function(){for(var t=new Array(this.length),e=0,r=this.head;null!==r;e++)t[e]=r.value,r=r.next;return t},n.prototype.toArrayReverse=function(){for(var t=new Array(this.length),e=0,r=this.tail;null!==r;e++)t[e]=r.value,r=r.prev;return t},n.prototype.slice=function(t,e){(e=e||this.length)<0&&(e+=this.length),(t=t||0)<0&&(t+=this.length);var r=new n;if(ethis.length&&(e=this.length);for(var o=0,i=this.head;null!==i&&othis.length&&(e=this.length);for(var o=this.length,i=this.tail;null!==i&&o>e;o--)i=i.prev;for(;null!==i&&o>t;o--,i=i.prev)r.push(i.value);return r},n.prototype.splice=function(t,e){t>this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(var r=0,n=this.head;null!==n&&r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),I(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;I(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function h(t){return function(t){if(Array.isArray(t))return p(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return p(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?p(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r>=0,r=String(void 0!==r?r:" "),t.length>e?String(t):((e-=t.length)>r.length&&(r+=r.repeat(e/r.length)),String(r.slice(0,e)+String(t)))}})),g=function(t){var e,r,n=t.status;return null==n&&(n=404),e=n,r=w(n),{status:e,message:r}},b=function(t,e){var r="success";return E.includes(e.status)||(r="failed"),t+" request "+r+" with status code: "+e.status+" Message: "+e.message},w=function(t){var e;switch(t){case 200:case 202:e="Success";break;case 400:e="Some of the mandatory fields in the message body are missing or invalid";break;case 401:e="The app doesn’t exist or the authentication failed";break;case 403:e="App traffic is blocked due to Zero package limit";break;default:e="Request failed"}return e},E=[200,202],x="appsflyer",S="logEvent",L=["af_revenue","af_price","af_currency","af_duration_seconds"],O="Invalid AppsFlyer SDK",I="Device OS not supported";function P(t){return P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},P(t)}function j(t,e){for(var r=0;r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:I(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function _(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function G(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){_(i,n,o,a,c,"next",t)}function c(t){_(i,n,o,a,c,"throw",t)}a(void 0)}))}}function C(t,e){for(var r=0;r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:I(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function Y(t){return Y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Y(t)}function B(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function H(t,e){for(var r=0;r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:I(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function at(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function ct(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){at(i,n,o,a,c,"next",t)}function c(t){at(i,n,o,a,c,"throw",t)}a(void 0)}))}}function ut(t,e){for(var r=0;r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:I(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function pt(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function vt(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){pt(i,n,o,a,c,"next",t)}function c(t){pt(i,n,o,a,c,"throw",t)}a(void 0)}))}}function yt(t,e){for(var r=0;r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:I(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function wt(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function Et(t,e){for(var r=0;r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:I(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function Gt(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function Ct(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){Gt(i,n,o,a,c,"next",t)}function c(t){Gt(i,n,o,a,c,"throw",t)}a(void 0)}))}}function Dt(t,e){for(var r=0;r 📑 API + +## AppsFlyerSDK Initialization + +** `await new AppsFlyerSDK(Object config)`** + +Initalization of the SDK + + +| Setting | Description | +| -------- | ------------- | +| devKey | Your application [devKey](https://support.appsflyer.com/hc/en-us/articles/207032066-Basic-SDK-integration-guide#retrieving-the-dev-key) provided by AppsFlyer (required) | +| appId | [App ID](https://support.appsflyer.com/hc/en-us/articles/207377436-Adding-a-new-app#available-in-the-app-store-google-play-store-windows-phone-store) you configured in your AppsFlyer dashboard (required) | +| isDebug | Show Debug logs - set to `true` for testing only! | +| isSandbox | Send events to sandbox endpoints - set to `true` for testing only! | + + + ```javascript +let appsflyer; +let config = { + devKey: "RxutGo4bSB9MKkM7bMCjHP", + appId: "3202204027284", + isDebug: true, + isSandbox: false +}; + +try{ + appsflyer = await new AppsFlyerSDK(config); +}catch(e){ + console.log(e); +} +``` + +## Launch event + +** `start()`** + +Send session to our servers + + + ```javascript +try{ + let response = await appsflyer.start(); + console.log("start API response success: " + JSON.stringify(response)); +}catch(err){ + console.log("start API response err: " + JSON.stringify(err)); +} + ``` + + +## In-app events + +** `logEvent(String eventName, Object eventValues)`** +| parameter | type | description | +| ----------- |----------|------------------------------------------ | +| eventName | String | The event name, it is presented in your dashboard. | +| eventValues | Object | The event values that are sent with the event. | + +Send in-app event + + + ```javascript + try{ + let response = await appsflyer.logEvent("af_purchase", {"af_revenue" : 1.99, "af_currency": "USD"}) + console.log("logEvent API response success: " + JSON.stringify(response)); + }catch(err){ + console.log("logEvent API response err: " + JSON.stringify(err)); + } + ``` + +## Set custom payload + +** `setCustomPayload(Object customPayload)`** + +Add custom payload. [You could use it to integrate other platforms](/docs/other-platforms.md) + + + ```javascript + let customPayload = { + "device_model": "3920X", + "device_os_version": "9.3.0", + "app_version": "1.0.5", + "device_id": "fa73d67d-f55c-5af3-883a-726253dc7d0e", + } + + appsflyer.setCustomPayload(customPayload); + ``` + + ## Set customer user Id + +** `setCustomerUserId(string customerUserId)`** + +Add customer user id. This will add `customer_user_id` key to the payload. + + + ```javascript + appsflyer.setCustomerUserId("123"); + ``` + + ## Init (Deprecated!) + +** `init(Object config)`** + +Please use `await new AppsFlyerSDK(config)` instead. + + ```javascript +let config = { + devKey: "RxutGo4bSB9MKkM7bMCjHP", + appId: "3202204027284", + isDebug: true, + isSandbox: false +} + +try{ + await appsflyer.init(config); +}catch(e){ + console.log(e); +} +``` \ No newline at end of file diff --git a/docs/other-platforms.md b/docs/other-platforms.md new file mode 100644 index 0000000..fa0e286 --- /dev/null +++ b/docs/other-platforms.md @@ -0,0 +1,55 @@ +# Support for other platforms + +AppsFlyerSDK support the following platforms: +- Vizio +- Vidaa + +In order to initalized the SDK: + +1. Initalize the SDK as explained. + +2. Add the following params using the `setCustomPayload` API: +- device_model +- device_os_version +- device_id +- app_version + +These fields are manadatory! +Make sure to provide them using the relevant platform APIs. A missing field will cause `400` response code by the SDK. + +```javascript +import AppsFlyerSDK from 'appsflyer-html5-ctv-sdk' + +let appsflyer; +let response; +let config = { + devKey: DEV_KEY, + appId: APP_ID, + isDebug: true, + isSandbox: false +} + +try{ + appsflyer = await new AppsFlyerSDK(config); +}catch(e){ + console.log(e); +} + +// Get the params using the relevant platform APIs and a provide the JSON object +let customPayload = { + "device_model": "3920X", + "device_os_version": "9.3.0", + "app_version": "1.0.5", + "device_id": "fa73d67d-f55c-5af3-883a-726253dc7d0e", +} +// Call the API +appsflyer.setCustomPayload(customPayload); + +try{ + response = await appsflyer.start(); + console.log("start API response success: " + JSON.stringify(response)); +}catch(err){ + console.log("start API response err: " + JSON.stringify(err)); +} +``` + \ No newline at end of file diff --git a/docs/testing.md b/docs/testing.md new file mode 100644 index 0000000..633158b --- /dev/null +++ b/docs/testing.md @@ -0,0 +1,65 @@ + +# Testing the integration + + +## Logs + +- In order to check a succesful integration of the AppsFlyer SDK, please enable `isDebug` option to `true`; + +- The following request should be sent: + +``` +// launch request: + +AppsFlyerSDK :: Sending start request +AppsFlyerSDK :: https://events.appsflyer.com/v1.0/c2s/session/app/tizen/3202204027284 +AppsFlyerSDK :: {"device_ids":[{"type":"custom","value":"c6577bb9-d4d1-4adf-809e-c3abf7c76b58"}],"limit_ad_tracking":true,"device_model":"UKS9000","device_os_version":"5.0","customer_user_id":"15667737-366d-4994-ac8b-653fe6b2be4a","app_version":"1.0.5","request_id":"aa64ea40-6cda-4fde-b4c5-31f600e1b50f","timestamp":1662035187532} + +// logEvent request: +AppsFlyerSDK :: Sending logEvent request +AppsFlyerSDK :: https://events.appsflyer.com/v1.0/c2s/inapp/app/tizen/3202204027284 +AppsFlyerSDK :: {"device_ids":[{"type":"custom","value":"c6577bb9-d4d1-4adf-809e-c3abf7c76b58"}],"limit_ad_tracking":true,"device_model":"UKS9000","device_os_version":"5.0","customer_user_id":"15667737-366d-4994-ac8b-653fe6b2be4a","app_version":"1.0.5","request_id":"c55bb0fe-fed5-4c02-8e5d-c6031f56ecaf","timestamp":1662035187534,"event_name":"af_purchase","event_parameters":{"af_revenue":1.99,"af_currency":"USD"}} + +``` + + +- Check the response code is 202/200 + +``` +AppsFlyerSDK :: start request success with status code: 202 Message: Success +AppsFlyerSDK :: logEvent request success with status code: 202 Message: Success +``` + + +## Response codes + +| response code | description | +| ----------- |------------------------------------------ | +| 200/202 | Successful | +| 400 | In case the authentication succeeded, if any of the mandatory fields in the message body are missing, or if any of the fields are invalid| +| 401 | If the app doesn’t exist or the authentication failed | +| 403 | In case app traffic should be blocked due to Zero package limit | +| 404 | network error | + + +## Sample app + +Try our demo app! + +1. Clone the repo + +2. Comment/uncomment the relevant config file for the relevant platform in example/main.js (LG/SAMSUNG) + +3. Execute the following: + +```bash +$ yarn buildDev +``` + +Open and run the following directory from your emulator/simulator or real device: + +``` +appsflyer-html5-ctv-sdk/example/app +``` + +![demo printscreen](https://github.com/AppsFlyerSDK/AppsFlyerSDK-appsflyer-html5-ctv-sdk/blob/main/images/demo.png?raw=true) diff --git a/example/app/index.html b/example/app/index.html index fddc2ef..1a2759a 100644 --- a/example/app/index.html +++ b/example/app/index.html @@ -19,11 +19,9 @@ - - - - + diff --git a/example/app/js/mainForBundle.js b/example/app/js/mainForBundle.js index 789629e..aba88c5 100644 --- a/example/app/js/mainForBundle.js +++ b/example/app/js/mainForBundle.js @@ -1,37 +1,57 @@ -const SAMSUNG_CONFIG = { +var SAMSUNG_CONFIG = { devKey: "RxutGo4bSB9MKkM7bMCjHP", appId: "3202204027284", isDebug: true, isSandbox: false }; -const LG_CONFIG = { +var LG_CONFIG = { devKey: "Jtef5xTpBf9M3rXtRhU2Fd", appId: "27022015", isDebug: true, isSandbox: false }; +var CUSTOM_CONFIG = { + devKey: "pJtNoWRvepn9EBtYG4jAUQ", + appId: "12345678", + isDebug: true, + isSandbox: false +} -async function main(){ - let appsflyer = AppsFlyerSDK.getInstance(); - let config = SAMSUNG_CONFIG; +function main(){ + var config = SAMSUNG_CONFIG; // config = LG_CONFIG; + config = CUSTOM_CONFIG; - await appsflyer.init(config); - + AppsFlyerSDK.getInstance(config).then(function(appsflyer){ + + console.log("AppsFlyerSDK initalized"); + + // // Add custom payload + var customPayload = { + "device_model": "3920X", + "device_os_version": "9.3.0", + "app_version": "1.0.5", + "device_id": "fa73d67d-f55c-5af3-883a-726253dc7d0e", + } + appsflyer.setCustomPayload(customPayload); + appsflyer.start() - .then((response)=>{ + .then(function(response){ console.log("start API response success: " + JSON.stringify(response)); - }).catch((err)=>{ + }).catch(function(err){ console.log("start API response err: " + JSON.stringify(err)); }); appsflyer.logEvent("af_purchase", {"af_revenue" : 1.99, "af_currency": "USD"}) - .then((response)=>{ + .then(function(response){ console.log("logEvent API response success: " + JSON.stringify(response)); - }).catch((err)=>{ + }).catch(function(err){ console.log("logEvent API response err: " + JSON.stringify(err)); }); - + + }).catch(function(err){ + console.log("AppsFlyerSDK initalized err: " + err); + }); } main(); \ No newline at end of file diff --git a/example/config.js b/example/config.js index 8491ef1..70b9241 100644 --- a/example/config.js +++ b/example/config.js @@ -9,4 +9,10 @@ export const LG_CONFIG = { appId: "27022015", isDebug: true, isSandbox: false +} +export const CUSTOM_CONFIG = { + devKey: "pJtNoWRvepn9EBtYG4jAUQ", + appId: "12345678", + isDebug: true, + isSandbox: false } \ No newline at end of file diff --git a/example/main.js b/example/main.js index ad94aa2..afa32d0 100644 --- a/example/main.js +++ b/example/main.js @@ -1,26 +1,44 @@ import AppsFlyerSDK from 'appsflyer-html5-ctv-sdk' -import {SAMSUNG_CONFIG, LG_CONFIG} from './config.js' +import {SAMSUNG_CONFIG, LG_CONFIG, CUSTOM_CONFIG} from './config.js' async function main(){ - let appsflyer = new AppsFlyerSDK(); + let appsflyer; + let response; let config = SAMSUNG_CONFIG; // config = LG_CONFIG; + // config = CUSTOM_CONFIG; - await appsflyer.init(config); + try{ + appsflyer = await new AppsFlyerSDK(config); + // appsflyer = await new AppsFlyerSDK(); + // await appsflyer.init(config); + }catch(e){ + console.log(e); + } + + // // Add custom payload + // let customPayload = { + // "device_model": "3920X", + // "device_os_version": "9.3.0", + // "app_version": "1.0.5", + // "device_id": "fa73d67d-f55c-5af3-883a-726253dc7d0e", + // } + // appsflyer.setCustomPayload(customPayload); - appsflyer.start() - .then((response)=>{ - console.log("start API response success: " + JSON.stringify(response)); - }).catch((err)=>{ - console.log("start API response err: " + JSON.stringify(err)); - }); + try{ + response = await appsflyer.start(); + console.log("start API response success: " + JSON.stringify(response)); + }catch(err){ + console.log("start API response err: " + JSON.stringify(err)); + } + + try{ + response = await appsflyer.logEvent("af_purchase", {"af_revenue" : 1.99, "af_currency": "USD"}) + console.log("logEvent API response success: " + JSON.stringify(response)); + }catch(err){ + console.log("logEvent API response err: " + JSON.stringify(err)); + } - appsflyer.logEvent("af_purchase", {"af_revenue" : 1.99, "af_currency": "USD"}) - .then((response)=>{ - console.log("logEvent API response success: " + JSON.stringify(response)); - }).catch((err)=>{ - console.log("logEvent API response err: " + JSON.stringify(err)); - }); } main(); \ No newline at end of file diff --git a/example/package.json b/example/package.json index 8d9a604..36ac03a 100644 --- a/example/package.json +++ b/example/package.json @@ -13,7 +13,7 @@ "devDependencies": { "@babel/preset-env": "~7.18.9", "babel-loader": "~8.2.5", - "webpack": "~5.73.0", + "webpack": "~5.84.1", "webpack-cli": "~4.10.0" }, "dependencies": { diff --git a/example/webpack.config.js b/example/webpack.config.js index 2001fb6..03e7187 100644 --- a/example/webpack.config.js +++ b/example/webpack.config.js @@ -26,4 +26,5 @@ export default { } ] }, + target: ['web', 'es5'] } \ No newline at end of file diff --git a/package.json b/package.json index dc0a1c0..71d46e6 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "eslint-config-google": "~0.14.0", "jest": "~28.1.3", "jest-fetch-mock": "~3.0.3", - "webpack": "~5.73.0", + "semver": "~7.3.8", + "webpack": "~5.84.1", "webpack-cli": "~4.10.0" } } diff --git a/src/AppsFlyerSDK.js b/src/AppsFlyerSDK.js index a2d38d0..f09a952 100644 --- a/src/AppsFlyerSDK.js +++ b/src/AppsFlyerSDK.js @@ -1,66 +1,104 @@ import AppsFlyerCore from './core/AppsFlyerCore.js'; -import AppsFlyerSamsungSDK from './platforms/samsung/samsung.js'; -import AppsFlyerLGSDK from './platforms/lg/lg.js'; +import Samsung from './platforms/samsung.js'; +import LG from './platforms/lg.js'; +import Vizio from './platforms/vizio.js'; +import Vidaa from './platforms/vidaa.js'; +import {INVALID_SDK, DEVICE_OS_NOT_SUPPORT, NO_PLATFORM_FOUND} from './core/utils/constants.js'; +import {Platform} from './platforms/utils/types.js'; +import semver from 'semver'; + +const PLATFORM_MAPPING = [Samsung, LG, Vizio, Vidaa] class AppsFlyerSDK { - constructor() { - this.appsflyerInstance = AppsFlyerCore.prototype.getInstance(); - this.setPlatformInstance(); + constructor(config) { + return new Promise( async(resolve, reject) => { + this.appsflyerInstance = AppsFlyerCore; + try{ + this.setPlatformInstance(); + await this.init(config); + resolve(this) + }catch(err){ + reject(err) + } + }); } setPlatformInstance() { - let platformInstance; - if (platformInstance === undefined) { - if (typeof tizen != 'undefined' && tizen.application) { - platformInstance = new AppsFlyerSamsungSDK(); - } else if (typeof webOS != 'undefined' && webOS.fetchAppInfo && webOS.platform.tv) { - platformInstance = new AppsFlyerLGSDK(); - } else { - platformInstance = null; - console.error("No platform found"); + try{ + const isDefined = x => x!= undefined; + const availablePlatforms = [(window.tizen && tizen.application), (window.webOS && webOS.fetchAppInfo && webOS.platform.tv), window.VIZIO, window.VIDAA]; + const plafromIndex = availablePlatforms.map(p => isDefined(p)).findIndex(p => p == true); + if(plafromIndex !== -1){ + const platformFactory = PLATFORM_MAPPING[plafromIndex]; + this.platformInstance = new platformFactory(); + }else{ + throw NO_PLATFORM_FOUND; } - this.platformInstance = platformInstance; + }catch(e){ + throw DEVICE_OS_NOT_SUPPORT; } } async init(config) { - if(this.platformInstance){ - let platformPayload, platformLogs; - try{ - platformPayload = await this.platformInstance.getPlatformPayload(); - platformLogs = this.platformInstance.getPlatformLogs(); - } catch (error){ - platformLogs.push(error) - } - - try{ - await this.appsflyerInstance.init(config, platformPayload, platformLogs); - } catch (error){ - console.error(error) + return new Promise( async(resolve, reject) => { + let platformData, platformLogs; + if(this.isSDKValid()){ + try{ + platformData = await this.platformInstance.getPlatformData(); + platformLogs = this.platformInstance.getPlatformLogs(); + } catch (error){ + platformLogs.push(error) + } + const isVersionValid = await this.validateOSVersion(platformData.platform, platformData.payload.device_os_version) + if(isVersionValid){ + try{ + await this.appsflyerInstance.init(config, platformData, platformLogs); + resolve(true) + } catch (error){ + reject(error) + } + }else{ + reject(DEVICE_OS_NOT_SUPPORT); + } + }else{ + reject(INVALID_SDK); } - } else { - console.error("Init failed: No platform found"); - } + }); } + start() { - return this.appsflyerInstance.start(); + return this.isSDKValid() ? this.appsflyerInstance.start() : new Error(INVALID_SDK); } logEvent(eventName, eventValue) { - return this.appsflyerInstance.logEvent(eventName, eventValue); + return this.isSDKValid() ? this.appsflyerInstance.logEvent(eventName, eventValue) : new Error(INVALID_SDK); } setCustomPayload(payload) { - return this.appsflyerInstance.setCustomPayload(payload); + return this.isSDKValid() ? this.appsflyerInstance.setCustomPayload(payload) : new Error(INVALID_SDK); } setCustomerUserId(userId) { - return this.appsflyerInstance.setCustomerUserId(userId); + return this.isSDKValid() ? this.appsflyerInstance.setCustomerUserId(userId) : new Error(INVALID_SDK); } + + async validateOSVersion(os, osVersion){ + if((os == Platform.Tizen || os == Platform.Webos) && semver.gte(semver.coerce(osVersion), '4.0.0')){ + return true + }else{ + let raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); + return raw ? parseInt(raw[2], 10) : false; + } + } + + isSDKValid(){ + return (this.appsflyerInstance && this.platformInstance) ? true : false; + } + } -export function getInstance(){ - return new AppsFlyerSDK(); +export async function getInstance(config){ + return new AppsFlyerSDK(config); } -export default AppsFlyerSDK; +export default (config) => new AppsFlyerSDK(config); diff --git a/src/core/AppsFlyerCore.js b/src/core/AppsFlyerCore.js index 3de52ea..a991877 100644 --- a/src/core/AppsFlyerCore.js +++ b/src/core/AppsFlyerCore.js @@ -3,7 +3,7 @@ import {Logger} from './utils/logger.js'; import {Auth} from './internal/auth/utils.js'; import {Requests} from './internal/http/requests.js'; import {LocalStorage} from './internal/storage/storage.js'; -import {APPSFLYER_INITIZALIZED, APPSFLYER_PREDEFINED_EVENTS, APPSFLYER_PREDEFINED_EVENTS_ARR, INVALID_APP_ID, INVALID_DEV_KEY, LOG_EVENT, START, CUSTOMER_USER_ID} from './utils/constants.js'; +import {APPSFLYER_INITIZALIZED, APPSFLYER_PREDEFINED_EVENTS, APPSFLYER_PREDEFINED_EVENTS_ARR, INVALID_APP_ID, INVALID_DEV_KEY, LOG_EVENT, START, CUSTOMER_USER_ID, DEVICE_ID, INVALID_CONFIG} from './utils/constants.js'; // AppsFlyerCore constructor and setters methods class AppsFlyerCore { @@ -25,9 +25,15 @@ class AppsFlyerCore { this.setPayload = function(payload) { this.payload = payload; }; - this.setCustomPayload = function(payload) { + this.setCustomPayload = function(payload) { Object.keys(payload).forEach((key) => { - if(!this.payload.hasOwnProperty(key)){ + if(key == DEVICE_ID){ + this.payload.device_ids.forEach(device_id => { + if(device_id.value == ""){ + device_id.value = payload[key]; + } + }); + }else{ this.payload[key] = payload[key]; } }) @@ -53,7 +59,7 @@ class AppsFlyerCore { appsFlyerID = this.utils.generateUUIDv4(); } this.appsFlyerID = appsFlyerID; - + // this.payload.appsflyer_id = appsFlyerID; this.payload.device_ids.push({type: 'custom', value: appsFlyerID}); }; @@ -80,61 +86,53 @@ class AppsFlyerCore { setCustomPayload(payload){ this.setCustomPayload(payload); } - - // getInstance API return AppsFlyerCore instance - getInstance() { - let client = this._instance; - if (client === undefined) { - client = new AppsFlyerCore(); - this._instance = client; - } - return client; - } + // init API sets appsFlyerOptions, sessionCount and AppsFlyer ID - async init(config, platformPayload, platformLogs) { - const appId = config.appId; - const devKey = config.devKey; - let isDebug = false; - let isSandbox = false; - - if (this.utils.isBooleanTrue(config.isDebug)) { - isDebug = true; - } - if (this.utils.isBooleanTrue(config.isSandbox)) { - isSandbox = true; - } - - this.logger.setDebugMode(isDebug); - this.printPlatformLogs(platformLogs); - - try { - if (!this.utils.isNumber(appId)) { - throw new Error(INVALID_APP_ID); - } - - if (!this.utils.isString(devKey)) { - throw new Error(INVALID_DEV_KEY); + async init(config, platformData, platformLogs) { + if(config != undefined && typeof config === 'object' && Object.keys(config).length !== 0){ + const appId = config.appId; + const devKey = config.devKey; + let isDebug = false; + let isSandbox = false; + + if (this.utils.isBooleanTrue(config.isDebug)) { + isDebug = true; + } + if (this.utils.isBooleanTrue(config.isSandbox)) { + isSandbox = true; } - - this.appsFlyerOptions.devKey = devKey; - this.appsFlyerOptions.appId = appId; - this.appsFlyerOptions.isDebug = isDebug; - this.appsFlyerOptions.isSandbox = isSandbox; - this.requests = new Requests(this.utils, this.logger, this.auth, this.storage, isSandbox); + this.logger.setDebugMode(isDebug); + this.printPlatformLogs(platformLogs); - this.setPayload(platformPayload.payload); - this.setPlatform(platformPayload.platform); - this.setAppsFlyerID(); - this.setSessionCount(); - this.setRequestID(); - this.setTimestamp(); - this.storage.setLocalStorage(this.appsFlyerID, this.sessionCount); + try { + if (!this.utils.isString(appId)) { + throw new Error(INVALID_APP_ID); + } - this.logger.info(APPSFLYER_INITIZALIZED); - } catch (err) { - this.logger.error(err); - throw new Error(err); + if (!this.utils.isString(devKey)) { + throw new Error(INVALID_DEV_KEY); + } + + this.appsFlyerOptions.devKey = devKey; + this.appsFlyerOptions.appId = appId; + this.appsFlyerOptions.isDebug = isDebug; + this.appsFlyerOptions.isSandbox = isSandbox; + + this.requests = new Requests(this.utils, this.logger, this.auth, this.storage, isSandbox); + this.setPayload(platformData.payload); + this.setPlatform(platformData.platform); + this.setAppsFlyerID(); + this.setSessionCount(); + this.setRequestID(); + this.setTimestamp(); + this.storage.setLocalStorage(this.appsFlyerID, this.sessionCount); + + this.logger.info(APPSFLYER_INITIZALIZED); + } catch (err) { + this.logger.error(err); + throw new Error(err); + } } } // start API send a request to session/first-open endpoint @@ -237,4 +235,4 @@ class AppsFlyerCore { } -export default AppsFlyerCore; +export default new AppsFlyerCore(); diff --git a/src/core/internal/auth/utils.js b/src/core/internal/auth/utils.js index f2771db..55460b2 100644 --- a/src/core/internal/auth/utils.js +++ b/src/core/internal/auth/utils.js @@ -1,22 +1,45 @@ export class Auth { constructor() { this.generateSignature = async function(key, message) { - const getUtf8Bytes = (str) => new Uint8Array( - [...unescape(encodeURIComponent(str))].map((c) => c.charCodeAt(0)), - ); + const getUtf8Bytes = (str) => new Uint8Array( + [...unescape(encodeURIComponent(str))].map((c) => c.charCodeAt(0)), + ); - const keyBytes = getUtf8Bytes(key); - const messageBytes = getUtf8Bytes(message); + const keyBytes = getUtf8Bytes(key); + const messageBytes = getUtf8Bytes(message); - const cryptoKey = await crypto.subtle.importKey( - 'raw', keyBytes, {name: 'HMAC', hash: 'SHA-256'}, - true, ['sign'], - ); - const sig = await crypto.subtle.sign('HMAC', cryptoKey, messageBytes); + const cryptoKey = await crypto.subtle.importKey( + 'raw', keyBytes, {name: 'HMAC', hash: 'SHA-256'}, + true, ['sign'], + ); + const sig = await crypto.subtle.sign('HMAC', cryptoKey, messageBytes); - // to lowercase hexits - const result = await [...new Uint8Array(sig)].map((b) => b.toString(16).padStart(2, '0')).join(''); - return result; + // to lowercase hexits + let result; + if (!String.prototype.padStart) { + result = [...new Uint8Array(sig)].map((b) => this.padStart(b.toString(16), 2, '0')).join(''); + }else{ + result = await [...new Uint8Array(sig)].map((b) => b.toString(16).padStart(2, '0')).join(''); + } + return result; + }; + + this.padStart = (strInput, targetLength,padString) => { + targetLength = targetLength>>0; //truncate if number or convert non-number to 0; + padString = String((typeof padString !== 'undefined' ? padString : ' ')); + + if (strInput.length > targetLength) { + return String(strInput); + } + else { + targetLength = targetLength-strInput.length; + if (targetLength > padString.length) { + padString += padString.repeat(targetLength/padString.length); //append to original to ensure we are longer than needed + } + return String(padString.slice(0,targetLength) + String(strInput)); + } }; } + + } diff --git a/src/core/internal/http/requests.js b/src/core/internal/http/requests.js index a49f6a0..b436422 100644 --- a/src/core/internal/http/requests.js +++ b/src/core/internal/http/requests.js @@ -105,8 +105,12 @@ export class Requests { this.postJson = async function(devKey, body) { const bodyString = JSON.stringify(body); - const signature = await this.auth.generateSignature(devKey, bodyString); - + let signature; + try{ + signature = await this.auth.generateSignature(devKey, bodyString); + }catch(e){ + throw new Error("Device OS is not supported") + } const options = { method: 'POST', headers: { @@ -116,7 +120,6 @@ export class Requests { }, body: bodyString, }; - return options; }; diff --git a/src/core/utils/constants.js b/src/core/utils/constants.js index e2bac8b..2d2c68e 100644 --- a/src/core/utils/constants.js +++ b/src/core/utils/constants.js @@ -4,6 +4,7 @@ export const APPSFLYER = 'appsflyer'; export const START = 'start'; export const LOG_EVENT = 'logEvent'; export const CUSTOMER_USER_ID = 'customer_user_id'; +export const DEVICE_ID = 'device_id'; // log events export const APPSFLYER_PREDEFINED_EVENTS = {Revenue: "af_revenue", Price: "af_price", Currency: "af_currency", Duration: "af_duration_seconds"}; @@ -12,6 +13,10 @@ export const APPSFLYER_PREDEFINED_EVENTS_ARR = ["af_revenue", "af_price", "af_cu // errors export const INVALID_APP_ID = 'Invalid appId!'; export const INVALID_DEV_KEY = 'Invalid devKey!'; +export const INVALID_SDK = 'Invalid AppsFlyer SDK'; +export const INVALID_CONFIG = 'Invalid Config file'; +export const DEVICE_OS_NOT_SUPPORT = 'Device OS not supported'; +export const NO_PLATFORM_FOUND = 'No platform found'; // events export const APPSFLYER_INITIZALIZED = 'AppsFlyer SDK initialized!'; diff --git a/src/core/utils/utils.js b/src/core/utils/utils.js index 0103516..dc5187f 100644 --- a/src/core/utils/utils.js +++ b/src/core/utils/utils.js @@ -19,11 +19,11 @@ export class Utils { return !(typeof (s) === 'string') || !(this.isEmptyString(s)); }; - this.isBooleanTrue = function isString(b) { + this.isBooleanTrue = function isBooleanTrue(b) { return (b === true && typeof (b) === 'boolean'); }; - this.isEmptyJSON = function isString(obj) { + this.isEmptyJSON = function isEmptyJSON(obj) { return (obj && Object.keys(obj).length === 0 && Object.getPrototypeOf(obj) === Object.prototype); }; diff --git a/src/platforms/custom.js b/src/platforms/custom.js new file mode 100644 index 0000000..86fd921 --- /dev/null +++ b/src/platforms/custom.js @@ -0,0 +1,34 @@ +import {platformData} from './utils/platformData.js'; +import {Platform, DeviceIds} from './utils/types.js'; + +class CustomPlatform { + constructor(platform){ + this.platform = platform; + this.platformLogs = []; + } + async getPlatformData() { + let data = platformData(this.platform); + let idType; + + switch(this.platform){ + case Platform.Smartcast: + idType = DeviceIds.Vida; + break; + case Platform.Vidaa: + idType = DeviceIds.Custom; + break; + default: + idType = DeviceIds.Custom; + } + + data.payload.device_ids.push({type: idType, value: ""}); + return data; + } + + getPlatformLogs() { + return this.platformLogs; + } + +} + +export default CustomPlatform; \ No newline at end of file diff --git a/src/platforms/lg/lg.js b/src/platforms/lg.js similarity index 69% rename from src/platforms/lg/lg.js rename to src/platforms/lg.js index df4ec25..2142744 100644 --- a/src/platforms/lg/lg.js +++ b/src/platforms/lg.js @@ -1,44 +1,37 @@ -import {PlatformPayload} from '../platformPayload.js'; -import {DEFAULT_DEVICE_ID, DEFAULT_APP_VERSION} from '../types/constants.js'; -import {DeviceIds, Platform} from '../types/types.js'; +import {platformData} from './utils/platformData.js'; +import {DEFAULT_DEVICE_ID, DEFAULT_APP_VERSION} from './utils/constants.js'; +import {DeviceIds, Platform} from './utils/types.js'; -class AppsFlyerLGSDK { +class LG { constructor(){ this.platformLogs = []; } - async getPlatformPayload() { - let lgPlatformPayload = PlatformPayload(Platform.Webos); - let lgUdid; - if (typeof webOS != 'undefined' && webOS.fetchAppInfo && webOS.platform.tv) { + async getPlatformData() { + let data = platformData(Platform.Webos); try { - lgUdid = await this.getLGUDID() - // if the device is a simulator, device ID should be zeros - if(lgUdid.includes("simulator")){ - lgUdid = DEFAULT_DEVICE_ID - } - lgPlatformPayload.payload.device_ids.push({type: DeviceIds.Lgudid, value: lgUdid}); + const lgUdid = await this.getLGUDID() + data.payload.device_ids.push({type: DeviceIds.Lgudid, value: lgUdid}); } catch (error) { this.platformLogs.push(error); } try { let deviceData = await this.getWebosData(); - lgPlatformPayload.payload.device_model = deviceData.device_model; - lgPlatformPayload.payload.device_os_version = deviceData.device_os_version; + data.payload.device_model = deviceData.device_model; + data.payload.device_os_version = deviceData.device_os_version; } catch (error) { this.platformLogs.push(error); } try { - let app_version = await this.getAppVersion(); - lgPlatformPayload.payload.app_version = app_version; + data.payload.app_version = await this.getAppVersion(); } catch (error) { - lgPlatformPayload.payload.app_version = DEFAULT_APP_VERSION; + data.payload.app_version = DEFAULT_APP_VERSION; this.platformLogs.push(error); } - return lgPlatformPayload; - } + return data; + } getPlatformLogs() { return this.platformLogs; @@ -100,6 +93,10 @@ class AppsFlyerLGSDK { if (isSucceeded){ let lgUdid = String(response.idList[0].idValue); + // if the device is a simulator, device ID should be zeros + if(lgUdid.includes("simulator")){ + lgUdid = DEFAULT_DEVICE_ID + } resolve(lgUdid); } }, @@ -111,4 +108,4 @@ class AppsFlyerLGSDK { } } -export default AppsFlyerLGSDK; \ No newline at end of file +export default LG; \ No newline at end of file diff --git a/src/platforms/samsung.js b/src/platforms/samsung.js new file mode 100644 index 0000000..b82799e --- /dev/null +++ b/src/platforms/samsung.js @@ -0,0 +1,83 @@ +import {platformData} from './utils/platformData.js'; +import {DEFAULT_DEVICE_ID, DEFAULT_APP_VERSION} from './utils/constants.js'; +import {DeviceIds, Platform} from './utils/types.js'; + +class Samsung { + constructor(){ + this.platformLogs = []; + } + async getPlatformData() { + let data = platformData(Platform.Tizen); + + data.payload.app_version = await this.getAppVersion(); + const limitAdTracking = await this.getIsLATEnabled(); + data.payload.limit_ad_tracking = limitAdTracking + + if(!limitAdTracking){ + const tifa = await this.getTIFA(); + if(tifa !== undefined){ + data.payload.device_ids.push({type: DeviceIds.Tifa, value: tifa}); + } + } + + data.payload.device_model = await this.getModel(); + data.payload.device_os_version = await this.getDeviceOsVersion(); + + return data; + } + + getPlatformLogs() { + return this.platformLogs; + } + + async getAppVersion() { + try{ + return await tizen.application.getCurrentApplication().appInfo.version; + } catch(e){ + this.platformLogs.push("Couldn't collect app version"); + return DEFAULT_APP_VERSION + } + } + async getIsLATEnabled() { + try{ + return await webapis.adinfo.isLATEnabled(); + } catch(e){ + if (e.message.indexOf('undefined') == -1) { + this.platformLogs.push('Error, such as a missing privilege in thee config.xml of the app'); + } else { + this.platformLogs.push('Older firmware and models do not support this method'); + } + return false; + } + } + async getTIFA() { + try { + return await webapis.adinfo.getTIFA(); + } catch (e) { + if (e.message.indexOf('undefined') == -1) { + this.platformLogs.push('Error, such as a missing privilege in thee config.xml of the app'); + } else { + this.platformLogs.push('Older firmware and models do not support this method'); + return DEFAULT_DEVICE_ID; + } + } + } + async getModel() { + try { + return await webapis.productinfo.getModel(); + } catch (e) { + this.platformLogs.push('permisson missing for device model'); + return "samsung"; + } + } + async getDeviceOsVersion() { + try { + return await tizen.systeminfo.getCapability('http://tizen.org/feature/platform.version'); + } catch (e) { + this.platformLogs.push('permisson missing for device model'); + } + } + +} + +export default Samsung; diff --git a/src/platforms/samsung/samsung.js b/src/platforms/samsung/samsung.js deleted file mode 100644 index 2b69e3d..0000000 --- a/src/platforms/samsung/samsung.js +++ /dev/null @@ -1,73 +0,0 @@ -import {PlatformPayload} from '../platformPayload.js'; -import {DEFAULT_DEVICE_ID, DEFAULT_APP_VERSION} from '../types/constants.js'; -import {DeviceIds, Platform} from '../types/types.js'; - -class AppsFlyerSamsungSDK { - constructor(){ - this.platformLogs = []; - } - async getPlatformPayload() { - let samsungPlatformPayload = PlatformPayload(Platform.Tizen); - try { - samsungPlatformPayload.payload = await this.getSamsungData(samsungPlatformPayload.payload); - } catch (error) { - this.platformLogs.push(error); - } - return samsungPlatformPayload; - } - getPlatformLogs() { - return this.platformLogs; - } - async getSamsungData(samsungPlatformPayload) { - let deviceData = samsungPlatformPayload; - if (typeof tizen != 'undefined' && tizen.application) { - let appVersion = DEFAULT_APP_VERSION; - try{ - appVersion = await tizen.application.getCurrentApplication().appInfo.version; - }catch(err){ - this.platformLogs.push("Couldn't collect app version"); - } - deviceData.app_version = appVersion; - - let isLATEnabled = true; - let tifa; - try { - isLATEnabled = await webapis.adinfo.isLATEnabled(); - if (!isLATEnabled) { - tifa = await webapis.adinfo.getTIFA(); - } - deviceData.limit_ad_tracking = isLATEnabled; - } catch (e) { - if (e.message.indexOf('undefined') == -1) { - this.platformLogs.push('Error, such as a missing privilege in thee config.xml of the app. Error: ' + e); - } else { - this.platformLogs.push('Older firmware and models do not support this method. Error: ' + e); - tifa = DEFAULT_DEVICE_ID; - } - } - if(tifa !== undefined){ - deviceData.device_ids.push({type: DeviceIds.Tifa, value: tifa}); - } - - let deviceModel = ''; - try { - deviceModel = await webapis.productinfo.getModel(); - deviceData.device_model = deviceModel; - } catch (e) { - this.platformLogs.push('permisson missing for device model Error: ' + e); - deviceData.device_model = "samsung"; - } - - let systeminfo = ''; - try { - systeminfo = await tizen.systeminfo.getCapability('http://tizen.org/feature/platform.version'); - deviceData.device_os_version = systeminfo; - } catch (e) { - this.platformLogs.push('permisson missing for device model Error: ' + e); - } - } - return deviceData; - } -} - -export default AppsFlyerSamsungSDK; diff --git a/src/platforms/types/constants.js b/src/platforms/utils/constants.js similarity index 100% rename from src/platforms/types/constants.js rename to src/platforms/utils/constants.js diff --git a/src/platforms/platformPayload.js b/src/platforms/utils/platformData.js similarity index 72% rename from src/platforms/platformPayload.js rename to src/platforms/utils/platformData.js index 77b0292..06302a6 100644 --- a/src/platforms/platformPayload.js +++ b/src/platforms/utils/platformData.js @@ -1,4 +1,4 @@ -export let PlatformPayload = function PlatformPayload(platform) { +export let platformData = (platform) => { return { platform: platform, payload: { diff --git a/src/platforms/types/types.js b/src/platforms/utils/types.js similarity index 77% rename from src/platforms/types/types.js rename to src/platforms/utils/types.js index 12869d2..885d48f 100644 --- a/src/platforms/types/types.js +++ b/src/platforms/utils/types.js @@ -1,7 +1,8 @@ export const Platform = { - Smartcast: "smartcast", Tizen: "tizen", Webos: "webos", + Smartcast: "smartcast", //vizio + Vidaa: "vidaa", } export const DeviceIds = { diff --git a/src/platforms/vidaa.js b/src/platforms/vidaa.js new file mode 100644 index 0000000..c8a0e9b --- /dev/null +++ b/src/platforms/vidaa.js @@ -0,0 +1,10 @@ +import {Platform} from './utils/types.js'; +import CustomPlatform from './custom.js'; + +class Vidaa extends CustomPlatform { + constructor(){ + super(Platform.Vidaa); + } +} + +export default Vidaa; \ No newline at end of file diff --git a/src/platforms/vizio.js b/src/platforms/vizio.js new file mode 100644 index 0000000..0511cf5 --- /dev/null +++ b/src/platforms/vizio.js @@ -0,0 +1,10 @@ +import {Platform} from './utils/types.js'; +import CustomPlatform from './custom.js'; + +class Vizio extends CustomPlatform { + constructor(){ + super(Platform.Smartcast); + } +} + +export default Vizio; \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index eb258c9..800007f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -22,4 +22,5 @@ export default { } ] }, + target: ['web', 'es5'] } \ No newline at end of file