react-native-expo-moengage
Version:
MoEngage Expo plugin for integrating MoEngage React-Native SDK
118 lines (117 loc) • 5.79 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.withMoEngageEntitlements = void 0;
const config_plugins_1 = require("@expo/config-plugins");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const plist = require('plist');
/**
* MoEngage Expo plugin for iOS - Entitlements modifications
*
* This plugin configures the app's entitlements file to enable MoEngage features by:
* 1. Reading the AppGroupName from the MoEngage configuration file
* 2. Adding app groups to entitlements for push notifications and extensions
* 3. Setting up keychain sharing if configured
* 4. Adding any other required entitlements for MoEngage features
*
* @param config - The Expo config object
* @param props - The MoEngage plugin properties
* @returns The updated config with modified entitlements
*/
const withMoEngageEntitlements = (config, props) => {
return (0, config_plugins_1.withEntitlementsPlist)(config, (config) => {
// Import configuration from plist file if specified
try {
const configFilePath = path.join(config.modRequest.projectRoot, props.apple.configFilePath);
if (fs.existsSync(configFilePath)) {
const configPlist = plist.parse(fs.readFileSync(configFilePath, 'utf8'));
// Add the app group to the main application target's entitlements if rich push or push templates are enabled
const appGroupsKey = 'com.apple.security.application-groups';
const appGroupValue = configPlist['AppGroupName'];
if (props.apple.pushTemplatesEnabled || props.apple.richPushNotificationEnabled || props.apple.pushNotificationImpressionTrackingEnabled) {
if (appGroupValue && appGroupValue.length > 0) {
const existingAppGroups = config.modResults[appGroupsKey];
if (Array.isArray(existingAppGroups)) {
if (!existingAppGroups.includes(appGroupValue)) {
config.modResults[appGroupsKey] = existingAppGroups.concat([appGroupValue]);
}
}
else {
config.modResults[appGroupsKey] = [appGroupValue];
}
}
else {
const message = `Missing AppGroupName key in MoEngage configuration`;
console.error(message);
throw new Error(message);
}
}
// Add the keychain access groups to the main application target's entitlements if specified
const keychainGroupsKey = 'keychain-access-groups';
const keychainGroupValue = configPlist['KeychainGroupName'];
const isStorageEncryptionEnabled = configPlist['IsStorageEncryptionEnabled'];
if (isStorageEncryptionEnabled && (!keychainGroupValue || keychainGroupValue.length == 0)) {
const message = `KeychainGroupName in "${configFilePath}" is required when IsStorageEncryptionEnabled is true`;
console.error(message);
throw new Error(message);
}
if (keychainGroupValue && keychainGroupValue.length > 0) {
const existingKeychainGroups = config.modResults[keychainGroupsKey];
if (Array.isArray(existingKeychainGroups)) {
if (!existingKeychainGroups.includes(keychainGroupValue)) {
config.modResults[keychainGroupsKey] = existingKeychainGroups.concat([keychainGroupValue]);
}
}
else {
config.modResults[keychainGroupsKey] = [keychainGroupValue];
}
}
}
else {
const message = `MoEngage configuration does not exist`;
console.error(message);
throw new Error(message);
}
}
catch (e) {
const message = `Could not import MoEngage configuration: ${e}`;
console.error(message);
throw new Error(message);
}
return config;
});
};
exports.withMoEngageEntitlements = withMoEngageEntitlements;