|
1624 | 1624 | * @param {function=} callback - Callback to notify with first param error and second param remote config object
|
1625 | 1625 | * */
|
1626 | 1626 | this.fetch_remote_config = function(keys, omit_keys, callback) {
|
| 1627 | + var keysFiltered = null; |
| 1628 | + var omitKeysFiltered = null; |
| 1629 | + var callbackFiltered = null; |
| 1630 | + |
| 1631 | + // check first param is truthy |
| 1632 | + if (keys) { |
| 1633 | + // if third parameter is falsy and first param is a function assign it as the callback function |
| 1634 | + if (!callback && typeof keys === "function") { |
| 1635 | + callbackFiltered = keys; |
| 1636 | + } |
| 1637 | + // else if first param is an array assign it as 'keys' |
| 1638 | + else if (Array.isArray(keys)) { |
| 1639 | + keysFiltered = keys; |
| 1640 | + } |
| 1641 | + } |
| 1642 | + // check second param is truthy |
| 1643 | + if (omit_keys) { |
| 1644 | + // if third parameter is falsy and second param is a function assign it as the callback function |
| 1645 | + if (!callback && typeof omit_keys === "function") { |
| 1646 | + callbackFiltered = omit_keys; |
| 1647 | + } |
| 1648 | + // else if second param is an array assign it as 'omit_keys' |
| 1649 | + else if (Array.isArray(omit_keys)) { |
| 1650 | + omitKeysFiltered = omit_keys; |
| 1651 | + } |
| 1652 | + } |
| 1653 | + // assign third param as a callback function if it was not assigned yet in first two params |
| 1654 | + if (!callbackFiltered && typeof callback === "function") { |
| 1655 | + callbackFiltered = callback; |
| 1656 | + } |
| 1657 | + |
1627 | 1658 | // use new RC API
|
1628 | 1659 | if (this.useExplicitRcApi) {
|
1629 | 1660 | log(logLevelEnums.INFO, "fetch_remote_config, Fetching remote config");
|
1630 | 1661 | // opt in is true(1) or false(0)
|
1631 | 1662 | var opt = this.rcAutoOptinAb ? 1 : 0;
|
1632 |
| - fetch_remote_config_explicit(keys, omit_keys, opt, callback); |
| 1663 | + fetch_remote_config_explicit(keysFiltered, omitKeysFiltered, opt, null, callbackFiltered); |
1633 | 1664 | return;
|
1634 | 1665 | }
|
1635 | 1666 |
|
1636 | 1667 | log(logLevelEnums.WARNING, "fetch_remote_config, Fetching remote config, with legacy API");
|
1637 |
| - fetch_remote_config_explicit(keys, omit_keys, "legacy", callback); |
| 1668 | + fetch_remote_config_explicit(keysFiltered, omitKeysFiltered, null, "legacy", callbackFiltered); |
1638 | 1669 | };
|
1639 | 1670 |
|
1640 | 1671 | /**
|
|
1651 | 1682 | method: "rc"
|
1652 | 1683 | };
|
1653 | 1684 | // check if keys were provided
|
1654 |
| - if (Array.isArray(arguments[0]) && arguments[0].length > 0) { |
1655 |
| - request.keys = JSON.stringify(arguments[0]); |
| 1685 | + if (keys.length > 0) { |
| 1686 | + request.keys = JSON.stringify(keys); |
1656 | 1687 | }
|
1657 | 1688 | // check if omit_keys were provided
|
1658 |
| - if (Array.isArray(arguments[1]) && arguments[1].length > 0) { |
1659 |
| - request.omit_keys = JSON.stringify(arguments[1]); |
| 1689 | + if (omit_keys.length > 0) { |
| 1690 | + request.omit_keys = JSON.stringify(omit_keys); |
1660 | 1691 | }
|
1661 |
| - var j = arguments.length - 1; |
1662 |
| - var provivedCall; |
1663 |
| - while (j--) { |
1664 |
| - // legacy api prompt check |
1665 |
| - if (arguments[j] === "legacy") { |
1666 |
| - request.method = "fetch_remote_config"; |
1667 |
| - } |
1668 |
| - // opted out/in check |
1669 |
| - if (arguments[j] === 0) { |
1670 |
| - request.oi = 0; |
1671 |
| - } |
1672 |
| - if (arguments[j] === 1) { |
1673 |
| - request.oi = 1; |
1674 |
| - } |
1675 |
| - // callback check |
1676 |
| - if (typeof arguments[j] === "function") { |
1677 |
| - provivedCall = arguments[j]; |
1678 |
| - } |
| 1692 | + var providedCall; |
| 1693 | + // legacy api prompt check |
| 1694 | + if (api === "legacy") { |
| 1695 | + request.method = "fetch_remote_config"; |
| 1696 | + } |
| 1697 | + // opted out/in check |
| 1698 | + if (optIn === 0) { |
| 1699 | + request.oi = 0; |
| 1700 | + } |
| 1701 | + if (optIn === 1) { |
| 1702 | + request.oi = 1; |
| 1703 | + } |
| 1704 | + // callback check |
| 1705 | + if (typeof callback === "function") { |
| 1706 | + providedCall = callback; |
1679 | 1707 | }
|
1680 | 1708 | if (self.check_consent(featureEnums.SESSIONS)) {
|
1681 | 1709 | request.metrics = JSON.stringify(getMetrics());
|
|
1704 | 1732 | catch (ex) {
|
1705 | 1733 | log(logLevelEnums.ERROR, "fetch_remote_config_explicit, Had an issue while parsing the response: " + ex);
|
1706 | 1734 | }
|
1707 |
| - if (provivedCall) { |
| 1735 | + if (providedCall) { |
1708 | 1736 | log(logLevelEnums.INFO, "fetch_remote_config_explicit, Callback function is provided");
|
1709 |
| - provivedCall(err, remoteConfigs); |
| 1737 | + providedCall(err, remoteConfigs); |
1710 | 1738 | }
|
1711 | 1739 | // JSON array can pass
|
1712 | 1740 | }, true);
|
1713 | 1741 | }
|
1714 | 1742 | else {
|
1715 | 1743 | log(logLevelEnums.ERROR, "fetch_remote_config_explicit, Remote config requires explicit consent");
|
1716 |
| - if (provivedCall) { |
1717 |
| - provivedCall(new Error("Remote config requires explicit consent"), remoteConfigs); |
| 1744 | + if (providedCall) { |
| 1745 | + providedCall(new Error("Remote config requires explicit consent"), remoteConfigs); |
1718 | 1746 | }
|
1719 | 1747 | }
|
1720 | 1748 | }
|
|
0 commit comments