From 9318e972568de23934da9b98f009018a1145b362 Mon Sep 17 00:00:00 2001 From: Jagadeesh Branch <102190347+JagadeeshKaricherla-branch@users.noreply.github.com> Date: Thu, 17 Aug 2023 09:13:49 -0700 Subject: [PATCH] refactor(sdk-1723): remove no-op code (#926) - refactor(sdk-1723): remove no-op code --- docs/web/2_table_of_contents.md | 8 +- src/2_resources.js | 24 ---- src/3_api.js | 7 -- src/6_branch.js | 214 -------------------------------- src/onpage.js | 9 -- test/3_api.js | 204 ------------------------------ test/6_branch.js | 77 ------------ test/integration-test.html | 2 +- 8 files changed, 3 insertions(+), 542 deletions(-) diff --git a/docs/web/2_table_of_contents.md b/docs/web/2_table_of_contents.md index bd5d47c0..e1549fe9 100644 --- a/docs/web/2_table_of_contents.md +++ b/docs/web/2_table_of_contents.md @@ -13,7 +13,6 @@ 3. Deep Linking + [.link()](#linkdata-callback) - + [.sendSMS()](#sendsmsphone-linkdata-options-callback) + [.deepview()](#deepviewdata-options-callback) + [.deepviewCta()](#deepviewcta) @@ -25,13 +24,10 @@ + [.setBranchViewData()](#setbranchviewdatadata) + [.closeJourney()](#closejourneycallback) -6. Firebase App Indexing - + [.autoAppIndex()](#autoappindexdata-callback) - -7. Revenue Analytics +6. Revenue Analytics + [.trackCommerceEvent()](#trackcommerceeventevent-commerce_data-metadata-callback) -8. User Privacy +7. User Privacy + [.disableTracking()](#disabletrackingdisabletracking) ___ diff --git a/src/2_resources.js b/src/2_resources.js index ec1ed5b7..dd2dc2c6 100644 --- a/src/2_resources.js +++ b/src/2_resources.js @@ -198,30 +198,6 @@ resources.deepview = { }) }; -resources.event = { - destination: config.api_endpoint, - endpoint: "/v1/event", - method: utils.httpMethod.POST, - params: defaults({ - "event": validator(true, validationTypes.STRING), - "metadata": validator(true, validationTypes.OBJECT), - "initial_referrer": validator(false, validationTypes.STRING), - "tracking_disabled": validator(false, validationTypes.BOOLEAN) - }) -}; - -resources.commerceEvent = { - destination: config.api_endpoint, - endpoint: "/v1/event", - method: utils.httpMethod.POST, - params: defaults({ - "event": validator(true, validationTypes.STRING), - "metadata": validator(false, validationTypes.OBJECT), - "initial_referrer": validator(false, validationTypes.STRING), - "commerce_data": validator(true, validationTypes.OBJECT) - }) -}; - // v2/event endpoints resources.logStandardEvent = { diff --git a/src/3_api.js b/src/3_api.js index 0362019b..73cb1726 100644 --- a/src/3_api.js +++ b/src/3_api.js @@ -143,13 +143,6 @@ } } - if (resource.endpoint === '/v1/event') { - d['metadata'] = safejson.stringify(d['metadata'] || {}); - if (d.hasOwnProperty('commerce_data')) { - d['commerce_data'] = safejson.stringify(d['commerce_data'] || {}); - } - } - if (resource.endpoint === '/v1/pageview' || resource.endpoint === '/v1/dismiss') { if (d['metadata']) { d['metadata'] = safejson.stringify(d['metadata'] || {}); diff --git a/src/6_branch.js b/src/6_branch.js index 4218ee2f..5005f0f7 100644 --- a/src/6_branch.js +++ b/src/6_branch.js @@ -1253,13 +1253,6 @@ Branch.prototype['link'] = wrap(callback_params.CALLBACK_ERR_DATA, function(done }); }); -/** =WEB - * @function Branch.sendSMS - * /** */ -Branch.prototype['sendSMS'] = function() { - console.warn("SMS feature has been deprecated. This is no-op."); -}; - /** * @function Branch.qrCode * @param {Object} linkData - _required_ - object of all link data, same as branch.link(). @@ -1516,24 +1509,6 @@ Branch.prototype._windowRedirect = function(url) { * }); * ``` * - * ___ - * - * # Referral system rewarding functionality - * In a standard referral system, you have 2 parties: the original user and the invitee. Our system - * is flexible enough to handle rewards for all users for any actions. Here are a couple example - * scenarios: - * 1. Reward the original user for taking action (eg. inviting, purchasing, etc) - * 2. Reward the invitee for installing the app from the original user's referral link - * 3. Reward the original user when the invitee takes action (eg. give the original user credit when - * their the invitee buys something) - * - * These reward definitions are created on the dashboard, under the 'Reward Rules' section in the - * 'Referrals' tab on the dashboard. - * - * Warning: For a referral program, you should not use unique awards for custom events and redeem - * pre-identify call. This can allow users to cheat the system. - * - * ___ * */ /*** +TOC_ITEM #deepviewcta &.deepviewCta()& ^ALL ***/ @@ -1555,186 +1530,6 @@ Branch.prototype['deepviewCta'] = wrap(callback_params.CALLBACK_ERR, function(do done(); }); -Branch.prototype['referrals'] = function() { - console.warn("Credits feature has been deprecated. This is no-op."); -}; - -/** - * Removing from documentation - */ -Branch.prototype['getCode'] = function() { - console.warn("Credits feature has been deprecated. This is no-op."); -}; - -/** - * Removing from documentation - */ -Branch.prototype['validateCode'] = function() { - console.warn("Credits feature has been deprecated. This is no-op."); -}; - -/** - * Removing from documentation - */ -Branch.prototype['applyCode'] = function() { - console.warn("Credits feature has been deprecated. This is no-op."); -}; - -/** - * @function Branch.credits - * @param {function(?Error,Object=)=} callback - _required_ - returns an object with credit data. - * - * **[Formerly `showCredits()`](CHANGELOG.md)** - * - * This call will retrieve the entire history of credits and redemptions from the individual user. - * - * ##### Usage - * ```js - * branch.credits( - * callback (err, data) - * ); - * ``` - * - * ##### Callback Format - * ```js - * callback( - * "Error message", - * { - * 'default': 15, - * 'other bucket': 9 - * } - * ); - * ``` - * - */ -/*** +TOC_HEADING &Credit Functions& ^ALL ***/ -/*** +TOC_ITEM #creditscallback &.credits()& ^ALL ***/ -Branch.prototype['credits'] = function() { - console.warn("Credits feature has been deprecated. This is no-op."); -}; -/** - * @function Branch.creditHistory - * @param {Object} options - _optional_ - options controlling the returned history - * @param {function(?Error,Object=)=} callback - _required_ - returns an array with credit history - * data - * - * This call will retrieve the entire history of credits and redemptions from the individual user. - * Properties available in the `options` object: - * - * | Key | Value - * | --- | --- - * | bucket | *optional (max 63 characters)* - The bucket from which to retrieve credit transactions. - * | begin_after_id | *optional* - The credit transaction id of the last item in the previous retrieval. Retrieval will start from the transaction next to it. If none is specified, retrieval starts from the very beginning in the transaction history, depending on the order. - * | length | *optional* - The number of credit transactions to retrieve. If none is specified, up to 100 credit transactions will be retrieved. - * | direction | **DEPRECATED** - The order of credit transactions to retrieve. If direction is `1`, retrieval is in least recent first order; If direction is `0`, or if none is specified, retrieval is in most recent first order. No longer supported. - * - * ##### Usage - * - * ```js - * branch.creditHistory( - * options, - * callback(err, data) - * ); - * ``` - * - * ##### Example - * - * ```js - * branch.creditHistory( - * { - * "length":50, - * "direction":0, // no longer supported. - * "begin_after_id":"123456789012345", - * "bucket":"default" - * } - * callback (err, data) - * ); - * ``` - * - * ##### Callback Format - * ```js - * callback( - * "Error message", - * [ - * { - * "transaction": { - * "date": "2014-10-14T01:54:40.425Z", - * "id": "50388077461373184", - * "bucket": "default", - * "type": 0, - * "amount": 5 - * }, - * "referrer": "12345678", - * "referree": null - * }, - * { - * "transaction": { - * "date": "2014-10-14T01:55:09.474Z", - * "id": "50388199301710081", - * "bucket": "default", - * "type": 2, - * "amount": -3 - * }, - * "referrer": null, - * "referree": "12345678" - * } - * ] - * ); - * ``` - * - * ___ - * - * ## Credit redemption - * - */ -/*** +TOC_ITEM #credithistoryoptions-callback &.creditHistory()& ^ALL ***/ -Branch.prototype['creditHistory'] = function() { - console.warn("Credits feature has been deprecated. This is no-op."); -}; - -/** - * @function Branch.redeem - * @param {number} amount - _required_ - an `amount` (int) of number of credits to redeem - * @param {string} bucket - _required_ - the name of the `bucket` (string) of which bucket to redeem the credits from - * @param {function(?Error)=} callback - _optional_ - returns an error if unsuccessful - * - * **[Formerly `redeemCredits()`](CHANGELOG.md)** - * - * Credits are stored in `buckets`, which you can define as points, currency, whatever makes sense - * for your app. When you want to redeem credits, call this method with the number of points to be - * redeemed, and the bucket to redeem them from. - * - * ```js - * branch.redeem( - * amount, // Amount of credits to be redeemed - * bucket, // String of bucket name to redeem credits from - * callback (err) - * ); - * ``` - * - * ##### Example - * - * ```js - * branch.redeem( - * 5, - * "Rubies", - * function(err) { - * console.log(err); - * } - * ); - * ``` - * - * ##### Callback Format - * ```js - * callback("Error message"); - * ``` - * ___ - */ -/*** +TOC_ITEM #redeemamount-bucket-callback &.redeem()& ^ALL ***/ -Branch.prototype['redeem'] = function() { - console.warn("Credits feature has been deprecated. This is no-op."); -}; - /** =WEB * @function Branch.addListener * @param {String} event - _optional_ - Specify which events you would like to listen for. If @@ -1992,15 +1787,6 @@ Branch.prototype['closeBanner'] = wrap(0, function(done) { done(); }); -/** - * @function Branch.autoAppIndex - * This is a deprecated function. - * ___ - */ -Branch.prototype['autoAppIndex'] = function() { - console.warn("autoAppIndex feature has been deprecated. This is no-op."); -}; - /** * @function Branch.trackCommerceEvent * @param {String} event - _required_ - Name of the commerce event to be tracked. We currently support 'purchase' events diff --git a/src/onpage.js b/src/onpage.js index 72665224..c436821c 100644 --- a/src/onpage.js +++ b/src/onpage.js @@ -34,29 +34,20 @@ }, [ 'addListener', - 'applyCode', - 'autoAppIndex', 'banner', 'closeBanner', 'closeJourney', - 'creditHistory', - 'credits', 'data', 'deepview', 'deepviewCta', 'first', - 'getCode', 'init', 'link', 'logout', - 'redeem', - 'referrals', 'removeListener', - 'sendSMS', 'setBranchViewData', 'setIdentity', 'track', - 'validateCode', 'trackCommerceEvent', 'logEvent', 'disableTracking', diff --git a/test/3_api.js b/test/3_api.js index e7af1b31..f86aa363 100644 --- a/test/3_api.js +++ b/test/3_api.js @@ -630,211 +630,7 @@ describe('Server', function() { }); }); - describe('/v1/event', function() { - var metadata = { - "url": "testurl", - "user_agent": "test_agent", - "language": "test_language" - }; - var metadataString = '&metadata=' + encodeURIComponent(JSON.stringify(metadata)); - beforeEach(function() { - requests = []; - storage.clear(); - }); - - it('should pass in branch_key, session_id, event and metadata', function(done) { - storage['set']('use_jsonp', false); - var assert = testUtils.plan(5, done); - - server.request( - resources.event, - testUtils.params({ "event": "testevent", "metadata": metadata }), - storage, - assert.done - ); - - assert.strictEqual(requests.length, 1, 'Request made'); - assert.strictEqual( - requests[0].url, - config.api_endpoint + '/v1/event', - 'Endpoint correct' - ); - assert.strictEqual(requests[0].method, 'POST', 'Method correct'); - assert.strictEqual( - requests[0].requestBody, - "event=testevent" + metadataString + - "&browser_fingerprint_id=" + browser_fingerprint_id + - "&identity_id=" + identity_id + - "&sdk=web" + config.version + - "&session_id=" + session_id + - "&branch_key=" + branch_sample_key - ); - - requests[0].respond( - 200, - { "Content-Type": "application/json" }, - '{ "session_id": 123 }' - ); - }); - - it('should pass as a jsonp request', function(done) { - var assert = testUtils.plan(3, done); - storage['set']('use_jsonp', true); - - var completeParams = testUtils.params({ - "event": "testevent", - "metadata": metadata - }); - server.request(resources.event, completeParams, storage, assert.done); - assert.strictEqual(requests.length, 1, 'Request made'); - - var encodedData = encodeURIComponent(utils.base64encode( - goog.json.serialize(completeParams) - )); - assert.strictEqual( - requests[0].src, - config.api_endpoint + '/v1/event?&data=' + encodedData + - '&callback=branch_callback__' + - (server._jsonp_callback_index - 1), - 'Endpoint correct' - ); - requests[0].callback(); - }); - - it('should fail without branch_key', function(done) { - var assert = testUtils.plan(2, done); - server.request( - resources.event, - testUtils.params( - { "event": "testevent", "metadata": metadata }, - [ 'branch_key' ] - ), - storage, - function(err) { - err = safejson.parse(err.message); - assert.strictEqual( - err.message, - "API request /v1/event missing parameter branch_key or app_id" - ); - } - ); - assert.strictEqual(requests.length, 0, 'No request made'); - }); - - it('should fail without session_id', function(done) { - var assert = testUtils.plan(2, done); - server.request( - resources.event, - testUtils.params( - { "event": "testevent", "metadata": metadata }, - [ 'session_id' ] - ), - storage, - function(err) { - err = safejson.parse(err.message); - assert.strictEqual( - err.message, - "API request /v1/event missing parameter session_id" - ); - } - ); - assert.strictEqual(requests.length, 0, 'No request made'); - }); - - it('should fail without event', function(done) { - var assert = testUtils.plan(2, done); - server.request( - resources.event, - testUtils.params({ "metadata": metadata }), - storage, - function(err) { - err = safejson.parse(err.message); - assert.strictEqual( - err.message, - "API request /v1/event missing parameter event" - ); - } - ); - assert.strictEqual(requests.length, 0, 'No request made'); - }); - - it('should fail without metadata', function(done) { - var assert = testUtils.plan(2, done); - server.request( - resources.event, - testUtils.params({ "event": "testevent" }), - storage, - function(err) { - err = safejson.parse(err.message); - assert.strictEqual( - err.message, - "API request /v1/event missing parameter metadata" - ); - } - ); - assert.strictEqual(requests.length, 0, 'No request made'); - }); - - // param format and type tests - it('should fail with metadata as string, not object', function(done) { - var assert = testUtils.plan(2, done); - server.request( - resources.event, - testUtils.params({ - "metadata": "Hello, I'm not an object.", - "event": "testevent" - }), - storage, function(err) { - err = safejson.parse(err.message); - assert.strictEqual( - err.message, - "API request /v1/event, parameter metadata is not an object" - ); - } - ); - assert.strictEqual(requests.length, 0, 'No request made'); - }); - }); - describe('API tests for trackingDisabled mode', function() { - it('Tests a request to v1/event with invalid data, tracking disabled and error callback disabled :: no requests should be made, no errors in callback', function(done) { - // This simulates a request being made from branch.init() - var assert = testUtils.plan(3, done); - utils.userPreferences.trackingDisabled = true; - utils.userPreferences.allowErrorsInCallback = false; - server.request( - resources.event, - testUtils.params({ - "name": "xyz" - }), - storage, function(err, data) { - assert.deepEqual({}, data, "data correct"); - assert.deepEqual(null, null, "error correct"); - } - ); - assert.strictEqual(requests.length, 0, 'No request made'); - }); - it('Tests a v1/event request with bogus data, tracking disabled and error callback enabled :: no requests should be made, error should be present in callback', function(done) { - // This simulates a call to branch.track() after branch is initialized - var assert = testUtils.plan(2, done); - utils.userPreferences.trackingDisabled = true; - utils.userPreferences.allowErrorsInCallback = true; - server.request( - resources.event, - testUtils.params({ - "name": "xyz" - }), - storage, function(err, data) { - assert.strictEqual( - err.message, - "Requested operation cannot be completed since tracking is disabled", - "Error message correct" - ); - assert.deepEqual(null, null, 'data correct'); - } - ); - assert.strictEqual(requests.length, 0, 'No request made'); - }); it('Tests a v1/open request, includes correct data, tracking disabled and error callback enabled :: request should go through', function(done) { // This simulates a call to v1/open as part of the Branch initialization process var assert = testUtils.plan(1, done); diff --git a/test/6_branch.js b/test/6_branch.js index a9d6a1a2..d528c78f 100644 --- a/test/6_branch.js +++ b/test/6_branch.js @@ -835,17 +835,6 @@ describe('Branch', function() { }); }); - describe('sendSMS', function() { - basicTests('sendSMS', [ 0 ]); - var spy = sinon.spy(console, 'warn'); - it('should print console warning about method deprecation for sendMS', function() { - var branch = initBranch(true); - var assert = testUtils.unplanned(); - branch.sendSMS(); - assert(spy.calledWith("SMS feature has been deprecated. This is no-op.")); - - }); - }); describe('banner', function() { basicTests('banner', [ 0 ]); @@ -1174,72 +1163,6 @@ describe('Branch', function() { }); }); }); - - describe('Credits', function() { - basicTests('referrals', [ 0 ]); - var spy = sinon.spy(console, 'warn'); - it('should print console warning about method deprecation for referrals', function() { - var branch = initBranch(true); - var assert = testUtils.unplanned(); - branch.referrals(); - assert(spy.calledWith("Credits feature has been deprecated. This is no-op.")); - - }); - it('should print console warning about method deprecation getCode', function() { - var branch = initBranch(true); - var assert = testUtils.unplanned(); - branch.getCode(); - assert(spy.calledWith("Credits feature has been deprecated. This is no-op.")); - - }); - it('should print console warning about method deprecation validateCode', function() { - var branch = initBranch(true); - var assert = testUtils.unplanned(); - branch.validateCode(); - assert(spy.calledWith("Credits feature has been deprecated. This is no-op.")); - - }); - it('should print console warning about method deprecation applyCode', function() { - var branch = initBranch(true); - var assert = testUtils.unplanned(); - branch.applyCode(); - assert(spy.calledWith("Credits feature has been deprecated. This is no-op.")); - - }); - it('should print console warning about method deprecation credits', function() { - var branch = initBranch(true); - var assert = testUtils.unplanned(); - branch.credits(); - assert(spy.calledWith("Credits feature has been deprecated. This is no-op.")); - - }); - it('should print console warning about method deprecation creditHistory', function() { - var branch = initBranch(true); - var assert = testUtils.unplanned(); - branch.creditHistory(); - assert(spy.calledWith("Credits feature has been deprecated. This is no-op.")); - - }); - it('should print console warning about method deprecation redeem', function() { - var branch = initBranch(true); - var assert = testUtils.unplanned(); - branch.redeem(); - assert(spy.calledWith("Credits feature has been deprecated. This is no-op.")); - - }); - }); - - describe('AppIndexing', function() { - basicTests('autoAppIndex', [ 0 ]); - var spy = sinon.spy(console, 'warn'); - it('should print console warning about method deprecation for autoAppIndex', function() { - var branch = initBranch(true); - var assert = testUtils.unplanned(); - branch.autoAppIndex(); - assert(spy.calledWith("autoAppIndex feature has been deprecated. This is no-op.")); - - }); - }); describe('addListener', function() { it('should add and remove an event listener to the branch object and fire', function(done) { var branch = initBranch(true); diff --git a/test/integration-test.html b/test/integration-test.html index 0a4645de..41920ce4 100644 --- a/test/integration-test.html +++ b/test/integration-test.html @@ -23,7 +23,7 @@