diff --git a/packages/react-native-branch/CHANGELOG.md b/packages/react-native-branch/CHANGELOG.md index 7ff85504..6a1ae2ff 100644 --- a/packages/react-native-branch/CHANGELOG.md +++ b/packages/react-native-branch/CHANGELOG.md @@ -1,3 +1,10 @@ +### @config-plugins/react-native-branch [1.0.2](https://github.com/expo/config-plugins/compare/@config-plugins/react-native-branch@1.0.1...@config-plugins/react-native-branch@1.0.2) (2022-03-22) + + +### Other chores + +* git ignore build folders ([#59](https://github.com/expo/config-plugins/issues/59)) ([d6050be](https://github.com/expo/config-plugins/commit/d6050beb2a5c68dc59287c27ec388c2002ec7904)) + ### @config-plugins/react-native-branch [1.0.1](https://github.com/expo/config-plugins/compare/@config-plugins/react-native-branch@1.0.0...@config-plugins/react-native-branch@1.0.1) (2022-03-16) diff --git a/packages/react-native-branch/build/types.d.ts b/packages/react-native-branch/build/types.d.ts new file mode 100644 index 00000000..09d7ea28 --- /dev/null +++ b/packages/react-native-branch/build/types.d.ts @@ -0,0 +1,5 @@ +export declare type ConfigData = { + apiKey?: string; + iosAppDomain?: string; + iosUniversalLinkDomains?: string[]; +}; diff --git a/packages/react-native-branch/build/types.js b/packages/react-native-branch/build/types.js new file mode 100644 index 00000000..c8ad2e54 --- /dev/null +++ b/packages/react-native-branch/build/types.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/packages/react-native-branch/build/withBranch.d.ts b/packages/react-native-branch/build/withBranch.d.ts new file mode 100644 index 00000000..b843b117 --- /dev/null +++ b/packages/react-native-branch/build/withBranch.d.ts @@ -0,0 +1,4 @@ +import type { ConfigPlugin } from "@expo/config-plugins"; +import type { ConfigData } from "./types"; +declare const _default: ConfigPlugin; +export default _default; diff --git a/packages/react-native-branch/build/withBranch.js b/packages/react-native-branch/build/withBranch.js new file mode 100644 index 00000000..4993b218 --- /dev/null +++ b/packages/react-native-branch/build/withBranch.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const config_plugins_1 = require("@expo/config-plugins"); +const withBranchAndroid_1 = require("./withBranchAndroid"); +const withBranchIOS_1 = require("./withBranchIOS"); +const withBranch = (config, { apiKey, iosAppDomain, iosUniversalLinkDomains } = {}) => { + config = withBranchAndroid_1.withBranchAndroid(config, { apiKey }); + config = withBranchIOS_1.withBranchIOS(config, { + apiKey, + iosAppDomain, + iosUniversalLinkDomains, + }); + return config; +}; +let pkg = { + name: "react-native-branch", +}; +try { + const branchPkg = require("react-native-branch/package.json"); + pkg = branchPkg; +} +catch (_a) { } +exports.default = config_plugins_1.createRunOncePlugin(withBranch, pkg.name, pkg.version); diff --git a/packages/react-native-branch/build/withBranchAndroid.d.ts b/packages/react-native-branch/build/withBranchAndroid.d.ts new file mode 100644 index 00000000..82fe9592 --- /dev/null +++ b/packages/react-native-branch/build/withBranchAndroid.d.ts @@ -0,0 +1,8 @@ +import { AndroidConfig } from "@expo/config-plugins"; +import type { ConfigPlugin } from "@expo/config-plugins"; +import type { ExpoConfig } from "@expo/config-types"; +export declare function getBranchApiKey(config: ExpoConfig): string | null; +export declare function setBranchApiKey(apiKey: string, androidManifest: AndroidConfig.Manifest.AndroidManifest): AndroidConfig.Manifest.AndroidManifest; +export declare const withBranchAndroid: ConfigPlugin<{ + apiKey?: string; +}>; diff --git a/packages/react-native-branch/build/withBranchAndroid.js b/packages/react-native-branch/build/withBranchAndroid.js new file mode 100644 index 00000000..5ba26091 --- /dev/null +++ b/packages/react-native-branch/build/withBranchAndroid.js @@ -0,0 +1,37 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.withBranchAndroid = exports.setBranchApiKey = exports.getBranchApiKey = void 0; +const config_plugins_1 = require("@expo/config-plugins"); +const { addMetaDataItemToMainApplication, getMainApplicationOrThrow, removeMetaDataItemFromMainApplication, } = config_plugins_1.AndroidConfig.Manifest; +const META_BRANCH_KEY = "io.branch.sdk.BranchKey"; +function getBranchApiKey(config) { + var _a, _b, _c, _d; + return (_d = (_c = (_b = (_a = config.android) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.branch) === null || _c === void 0 ? void 0 : _c.apiKey) !== null && _d !== void 0 ? _d : null; +} +exports.getBranchApiKey = getBranchApiKey; +function setBranchApiKey(apiKey, androidManifest) { + const mainApplication = getMainApplicationOrThrow(androidManifest); + if (apiKey) { + // If the item exists, add it back + addMetaDataItemToMainApplication(mainApplication, META_BRANCH_KEY, apiKey); + } + else { + // Remove any existing item + removeMetaDataItemFromMainApplication(mainApplication, META_BRANCH_KEY); + } + return androidManifest; +} +exports.setBranchApiKey = setBranchApiKey; +const withBranchAndroid = (config, data) => { + var _a; + const apiKey = (_a = data.apiKey) !== null && _a !== void 0 ? _a : getBranchApiKey(config); + if (!apiKey) { + throw new Error("Branch API key is required"); + } + config = config_plugins_1.withAndroidManifest(config, (config) => { + config.modResults = setBranchApiKey(apiKey, config.modResults); + return config; + }); + return config; +}; +exports.withBranchAndroid = withBranchAndroid; diff --git a/packages/react-native-branch/build/withBranchIOS.d.ts b/packages/react-native-branch/build/withBranchIOS.d.ts new file mode 100644 index 00000000..c4adecae --- /dev/null +++ b/packages/react-native-branch/build/withBranchIOS.d.ts @@ -0,0 +1,6 @@ +import type { ConfigPlugin, InfoPlist } from "@expo/config-plugins"; +import type { ExpoConfig } from "@expo/config-types"; +import type { ConfigData } from "./types"; +export declare function getBranchApiKey(config: Pick): string | null; +export declare function setBranchApiKey(apiKey: string, infoPlist: InfoPlist): InfoPlist; +export declare const withBranchIOS: ConfigPlugin; diff --git a/packages/react-native-branch/build/withBranchIOS.js b/packages/react-native-branch/build/withBranchIOS.js new file mode 100644 index 00000000..c658c2ff --- /dev/null +++ b/packages/react-native-branch/build/withBranchIOS.js @@ -0,0 +1,52 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.withBranchIOS = exports.setBranchApiKey = exports.getBranchApiKey = void 0; +const config_plugins_1 = require("@expo/config-plugins"); +function getBranchApiKey(config) { + var _a, _b, _c, _d; + return (_d = (_c = (_b = (_a = config.ios) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.branch) === null || _c === void 0 ? void 0 : _c.apiKey) !== null && _d !== void 0 ? _d : null; +} +exports.getBranchApiKey = getBranchApiKey; +function setBranchApiKey(apiKey, infoPlist) { + if (apiKey === null) { + return infoPlist; + } + return { + ...infoPlist, + branch_key: { + live: apiKey, + }, + }; +} +exports.setBranchApiKey = setBranchApiKey; +const withBranchIOS = (config, data) => { + var _a; + // Ensure object exist + if (!config.ios) { + config.ios = {}; + } + const apiKey = (_a = data.apiKey) !== null && _a !== void 0 ? _a : getBranchApiKey(config); + if (!apiKey) { + throw new Error("Branch API key is required"); + } + // Update the infoPlist with the branch key and branch domain + config = config_plugins_1.withInfoPlist(config, (config) => { + config.modResults = setBranchApiKey(apiKey, config.modResults); + if (data.iosAppDomain) { + config.modResults.branch_app_domain = data.iosAppDomain; + } + else { + delete config.modResults.branch_app_domain; + } + if (data.iosUniversalLinkDomains) { + config.modResults.branch_universal_link_domains = + data.iosUniversalLinkDomains; + } + else { + delete config.modResults.branch_universal_link_domains; + } + return config; + }); + return config; +}; +exports.withBranchIOS = withBranchIOS; diff --git a/packages/react-native-branch/package.json b/packages/react-native-branch/package.json index bfda6552..1aca6d78 100644 --- a/packages/react-native-branch/package.json +++ b/packages/react-native-branch/package.json @@ -1,6 +1,6 @@ { "name": "@config-plugins/react-native-branch", - "version": "1.0.1", + "version": "1.0.2", "description": "Config plugin to auto configure react-native-branch on prebuild", "author": "650 Industries, Inc.", "license": "MIT",