codeplay-common 4.11.23 → 4.11.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/files/buildCodeplay/codeplayBeforeBuild.js +4753 -4785
- package/files/buildCodeplay/ios-ad-consent.cjs +56 -0
- package/files/buildCodeplay/ruads.cjs +101 -2
- package/files/buildCodeplay/setup-ruads.cjs +7 -1
- package/files/finalrelease +3 -0
- package/package.json +1 -1
- package/scripts/ios-ad-consent.test.cjs +99 -0
- package/scripts/ruads-install.test.cjs +18 -0
- package/scripts/ruads-policy.test.cjs +130 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Version 1.0: keep native app lifecycle callbacks out of the UMP/ATT flow.
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
// Only remove the known block generated by older builds. Any other native
|
|
6
|
+
// request needs an explicit correction rather than deleting custom app code.
|
|
7
|
+
const legacyRequest = [
|
|
8
|
+
'if ATTrackingManager.trackingAuthorizationStatus == .notDetermined &&',
|
|
9
|
+
'!isTrackingAuthorizationRequestScheduled {',
|
|
10
|
+
'isTrackingAuthorizationRequestScheduled = true',
|
|
11
|
+
'DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in',
|
|
12
|
+
'self?.isTrackingAuthorizationRequestScheduled = false',
|
|
13
|
+
'guard UIApplication.shared.applicationState == .active,',
|
|
14
|
+
'ATTrackingManager.trackingAuthorizationStatus == .notDetermined else { return }',
|
|
15
|
+
'ATTrackingManager.requestTrackingAuthorization { _ in }',
|
|
16
|
+
'}',
|
|
17
|
+
'}',
|
|
18
|
+
].map(line => line.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/ +/g, '\\s+')).join('\\s*');
|
|
19
|
+
|
|
20
|
+
function nativeSources(directory) {
|
|
21
|
+
if (!fs.existsSync(directory)) return [];
|
|
22
|
+
return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
|
|
23
|
+
const file = path.join(directory, entry.name);
|
|
24
|
+
if (entry.isDirectory()) return nativeSources(file);
|
|
25
|
+
return entry.isFile() && /\.(?:swift|m|mm)$/.test(entry.name) ? [file] : [];
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function prepareIOSAdConsent(projectRoot, log = console.log) {
|
|
30
|
+
const appDirectory = path.join(projectRoot, 'ios', 'App', 'App');
|
|
31
|
+
const updates = [];
|
|
32
|
+
for (const file of nativeSources(appDirectory)) {
|
|
33
|
+
const original = fs.readFileSync(file, 'utf8');
|
|
34
|
+
let content = original;
|
|
35
|
+
if (path.basename(file) === 'SceneDelegate.swift') {
|
|
36
|
+
content = content.replace(new RegExp(legacyRequest, 'g'), '');
|
|
37
|
+
content = content.replace(/^[ \t]*private var isTrackingAuthorizationRequestScheduled = false\r?\n/gm, '');
|
|
38
|
+
if (!content.includes('ATTrackingManager')) {
|
|
39
|
+
content = content.replace(/^import AppTrackingTransparency\r?\n/gm, '');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Check AppDelegate and other app-owned startup code even when this app
|
|
43
|
+
// has no SceneDelegate. The Capacitor plugin remains the single ATT owner.
|
|
44
|
+
const executable = content.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/[^\r\n]*/g, '');
|
|
45
|
+
if (/\bATTrackingManager\s*(?:\.\s*|\s+)requestTrackingAuthorization(?:WithCompletionHandler)?\b/.test(executable)) {
|
|
46
|
+
throw new Error(`${path.relative(projectRoot, file)} requests ATT outside the regional consent flow. Remove the native startup request; @admob requests ATT after UMP completes.`);
|
|
47
|
+
}
|
|
48
|
+
if (content !== original) updates.push({ file, content });
|
|
49
|
+
}
|
|
50
|
+
// Validate every source before changing any file.
|
|
51
|
+
for (const { file, content } of updates) fs.writeFileSync(file, content, 'utf8');
|
|
52
|
+
log('iOS native startup checked; the ad consent flow controls ATT after UMP.');
|
|
53
|
+
return updates.map(({ file }) => path.relative(projectRoot, file));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { prepareIOSAdConsent };
|
|
@@ -4,6 +4,101 @@ const { execFileSync } = require('child_process');
|
|
|
4
4
|
|
|
5
5
|
const VK_PACKAGE = 'capacitor-codeplay-rustore-ads';
|
|
6
6
|
const ADMOB_PACKAGE = 'capacitor-admob-nextgen';
|
|
7
|
+
const noAdmobStart = '// BEGIN CODEPLAY EXCLUDE ADMOB';
|
|
8
|
+
const noAdmobEnd = '// END CODEPLAY EXCLUDE ADMOB';
|
|
9
|
+
|
|
10
|
+
function removeAdmobPluginConfig(config) {
|
|
11
|
+
for (const name of Object.keys(config.plugins || {})) {
|
|
12
|
+
if (/admob/i.test(name)) delete config.plugins[name];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// IAP shares this JSON with AdMob. Keep purchase settings but omit ad IDs from
|
|
17
|
+
// non-AdMob web bundles, without editing the app's protected source config.
|
|
18
|
+
function admobConfigPlugin(provider) {
|
|
19
|
+
return {
|
|
20
|
+
name: 'codeplay-store-admob-config',
|
|
21
|
+
enforce: 'pre',
|
|
22
|
+
transform(source, id) {
|
|
23
|
+
if (provider === 'admob' || !/(?:^|[\\/])admob-ad-configuration(?:-nextgen)?\.json$/.test(id)) return null;
|
|
24
|
+
const scrub = value => {
|
|
25
|
+
if (typeof value === 'string') return value.startsWith('ca-app-pub-') ? '' : value;
|
|
26
|
+
if (Array.isArray(value)) return value.map(scrub);
|
|
27
|
+
if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, scrub(item)]));
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
const config = scrub(JSON.parse(source));
|
|
31
|
+
for (const key of ['bannerEnabled', 'interstitialEnabled', 'appOpenEnabled', 'rewardVideoEnabled', 'rewardInterstitialEnabled']) {
|
|
32
|
+
if (config.config) config.config[key] = false;
|
|
33
|
+
}
|
|
34
|
+
return { code: JSON.stringify(config), map: null };
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Run after sync as well as before builds: old app-owned entries survive cap sync.
|
|
40
|
+
// Keep ads-identifier/appset: VK and analytics use them independently of AdMob.
|
|
41
|
+
function syncAndroidAdmobPolicy(projectRoot, storeId, platform = 'android') {
|
|
42
|
+
if (platform !== 'android') return false;
|
|
43
|
+
const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json'), 'utf8'));
|
|
44
|
+
const excluded = getAdProvider(config, storeId, platform) !== 'admob';
|
|
45
|
+
let changed = false;
|
|
46
|
+
const update = (file, transform) => {
|
|
47
|
+
if (!fs.existsSync(file)) return;
|
|
48
|
+
const original = fs.readFileSync(file, 'utf8');
|
|
49
|
+
const next = transform(original);
|
|
50
|
+
if (next === original) return;
|
|
51
|
+
fs.writeFileSync(file, next);
|
|
52
|
+
changed = true;
|
|
53
|
+
};
|
|
54
|
+
update(path.join(projectRoot, 'android/app/build.gradle'), original => {
|
|
55
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
56
|
+
const clean = original.replace(new RegExp(`^${noAdmobStart}[\\s\\S]*?${noAdmobEnd}\\r?\\n?`, 'gm'), '');
|
|
57
|
+
if (!excluded) return clean;
|
|
58
|
+
const modules = ['play-services-ads', 'play-services-ads-lite', 'play-services-ads-base',
|
|
59
|
+
'play-services-ads-api', 'play-services-ads-fullscreen', 'play-services-ads-mobile-sdk'];
|
|
60
|
+
const block = [noAdmobStart, 'configurations.configureEach {',
|
|
61
|
+
...modules.map(name => ` exclude group: 'com.google.android.gms', module: '${name}'`),
|
|
62
|
+
" exclude group: 'com.google.ads.mediation'",
|
|
63
|
+
" exclude group: 'com.google.android.ump', module: 'user-messaging-platform'",
|
|
64
|
+
'}', noAdmobEnd, ''].join(newline);
|
|
65
|
+
return `${clean.trimEnd()}${newline}${newline}${block}`;
|
|
66
|
+
});
|
|
67
|
+
if (!excluded) {
|
|
68
|
+
const readJson = file => fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
|
|
69
|
+
const adSettings = readJson(path.join(projectRoot, 'src/js/Ads/admob-ad-configuration-nextgen.json'));
|
|
70
|
+
const pkg = readJson(path.join(projectRoot, 'package.json'));
|
|
71
|
+
const appId = adSettings.androidAppId || pkg.admob?.androidAppId || config.plugins?.AdMob?.APP_ID_ANDROID;
|
|
72
|
+
update(path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml'), original => {
|
|
73
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
74
|
+
let next = original;
|
|
75
|
+
const ensureMeta = (name, value) => {
|
|
76
|
+
const escapedName = name.replace(/\./g, '\\.');
|
|
77
|
+
const existing = new RegExp(`<meta-data\\b(?=[^>]*\\bandroid:name\\s*=\\s*(['"])${escapedName}\\1)[^>]*(?:/\\s*>|>[\\s\\S]*?</meta-data\\s*>)`);
|
|
78
|
+
const tag = `<meta-data android:name="${name}" android:value="${value}" />`;
|
|
79
|
+
next = existing.test(next) ? next.replace(existing, tag)
|
|
80
|
+
: next.replace(/<application\b[^>]*>/, match => `${match}${newline} ${tag}`);
|
|
81
|
+
};
|
|
82
|
+
if (appId) ensureMeta('com.google.android.gms.ads.APPLICATION_ID', appId);
|
|
83
|
+
if (!next.includes('com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING')) {
|
|
84
|
+
ensureMeta('com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING', 'true');
|
|
85
|
+
}
|
|
86
|
+
if (adSettings.config?.isKidsApp !== true && !next.includes('com.google.android.gms.permission.AD_ID')) {
|
|
87
|
+
next = next.replace('</manifest>', ` <uses-permission android:name="com.google.android.gms.permission.AD_ID" />${newline}</manifest>`);
|
|
88
|
+
}
|
|
89
|
+
return next;
|
|
90
|
+
});
|
|
91
|
+
return changed;
|
|
92
|
+
}
|
|
93
|
+
update(path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml'), original =>
|
|
94
|
+
original.replace(/^[ \t]*<(meta-data|activity|service|provider|receiver|uses-library)\b(?=[^>]*\bandroid:name\s*=\s*(['"])(?:com\.google\.android\.gms\.ads\.|com\.google\.ads\.|com\.google\.android\.ump\.)[^'"]*\2)[^>]*(?:\/\s*>|>[\s\S]*?<\/\1\s*>)[ \t]*(?:\r?\n)?/gm, ''));
|
|
95
|
+
update(path.join(projectRoot, 'android/app/src/main/assets/capacitor.config.json'), original => {
|
|
96
|
+
const generated = JSON.parse(original);
|
|
97
|
+
removeAdmobPluginConfig(generated);
|
|
98
|
+
return JSON.stringify(generated, null, 2) + '\n';
|
|
99
|
+
});
|
|
100
|
+
return changed;
|
|
101
|
+
}
|
|
7
102
|
|
|
8
103
|
// A missing RuAds section preserves the existing provider on every store.
|
|
9
104
|
function getAdProvider(config, storeId, platform = 'android') {
|
|
@@ -103,9 +198,13 @@ function withNativeAdProvider(projectRoot, storeId, platform, action) {
|
|
|
103
198
|
config[target] = { ...config[target], includePlugins: includedPackages(config, pkg, target,
|
|
104
199
|
getAdProvider(config, storeId, target)) };
|
|
105
200
|
}
|
|
201
|
+
if (provider !== 'admob') removeAdmobPluginConfig(config);
|
|
106
202
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
|
|
107
|
-
|
|
203
|
+
let result;
|
|
204
|
+
try { result = action(provider); }
|
|
108
205
|
finally { fs.writeFileSync(configPath, original); }
|
|
206
|
+
syncAndroidAdmobPolicy(projectRoot, storeId, platform);
|
|
207
|
+
return result;
|
|
109
208
|
}
|
|
110
209
|
|
|
111
|
-
module.exports = { getAdProvider, controllerPath, findLatestVkController, prepareReleaseAds, includedPackages, syncAdProviderPackages, withNativeAdProvider };
|
|
210
|
+
module.exports = { getAdProvider, controllerPath, findLatestVkController, prepareReleaseAds, includedPackages, syncAdProviderPackages, withNativeAdProvider, syncAndroidAdmobPolicy, admobConfigPlugin };
|
|
@@ -29,12 +29,18 @@ export default async (environment) => {
|
|
|
29
29
|
const alias = !selected ? aliases : Array.isArray(aliases)
|
|
30
30
|
? aliases.map(item => item.find === '@admob' ? { ...item, replacement: selected } : item)
|
|
31
31
|
: { ...aliases, '@admob': selected };
|
|
32
|
-
return { ...base, resolve: { ...base.resolve, alias }, define: { ...base.define,
|
|
32
|
+
return { ...base, plugins: [...(base.plugins || []), ruAdsBuild.admobConfigPlugin(provider)], resolve: { ...base.resolve, alias }, define: { ...base.define,
|
|
33
33
|
'import.meta.env.VITE_STORE_ID': JSON.stringify(storeId),
|
|
34
34
|
'import.meta.env.VITE_RUADS_ENABLED': JSON.stringify(provider === 'vk') } };
|
|
35
35
|
};
|
|
36
36
|
`);
|
|
37
37
|
}
|
|
38
|
+
const current = fs.readFileSync(vite, 'utf8');
|
|
39
|
+
if (current.includes('codeplayOriginalViteConfig') && !current.includes('ruAdsBuild.admobConfigPlugin(')) {
|
|
40
|
+
const updated = current.replace('return { ...base, resolve:', 'return { ...base, plugins: [...(base.plugins || []), ruAdsBuild.admobConfigPlugin(provider)], resolve:');
|
|
41
|
+
if (updated === current) throw new Error('Cannot install store AdMob config filtering in the Vite wrapper.');
|
|
42
|
+
fs.writeFileSync(vite, updated);
|
|
43
|
+
}
|
|
38
44
|
}
|
|
39
45
|
const ru = config.plugins?.RuAds;
|
|
40
46
|
if (ru?.VK_ADS_ENABLED !== true || !(ru.STORE_IDS || []).some(id => [4, 10].includes(Number(id)))) return;
|
package/files/finalrelease
CHANGED
|
@@ -1233,6 +1233,9 @@ rl.question('Enter new versionCode (press enter to keep current): ', (newVersion
|
|
|
1233
1233
|
execSync('npx cap sync android', { stdio: 'inherit',
|
|
1234
1234
|
env: { ...process.env, VITE_STORE_ID: String(id), CODEPLAY_BUILD_PLATFORM: 'android' } }));
|
|
1235
1235
|
|
|
1236
|
+
// Reapply after sync so stale settings cannot leak from another store.
|
|
1237
|
+
ruAdsBuild.syncAndroidAdmobPolicy(__dirname, id, 'android');
|
|
1238
|
+
|
|
1236
1239
|
if (!baselineProfileChecked) {
|
|
1237
1240
|
await checkBaselineProfileBeforeRelease();
|
|
1238
1241
|
baselineProfileChecked = true;
|
package/package.json
CHANGED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { prepareIOSAdConsent } = require('../files/buildCodeplay/ios-ad-consent.cjs');
|
|
6
|
+
const { createRequire } = require('node:module');
|
|
7
|
+
const vm = require('node:vm');
|
|
8
|
+
const { install } = require('./sync-files.js');
|
|
9
|
+
|
|
10
|
+
function fixture(t, sources) {
|
|
11
|
+
const tempRoot = path.resolve(__dirname, '../agent-temp/ios-ad-consent-tests');
|
|
12
|
+
fs.mkdirSync(tempRoot, { recursive: true });
|
|
13
|
+
const root = fs.mkdtempSync(path.join(tempRoot, 'case-'));
|
|
14
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
15
|
+
for (const [name, content] of Object.entries(sources)) {
|
|
16
|
+
const file = path.join(root, 'ios/App/App', name);
|
|
17
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
18
|
+
fs.writeFileSync(file, content);
|
|
19
|
+
}
|
|
20
|
+
return { root, read: name => fs.readFileSync(path.join(root, 'ios/App/App', name), 'utf8') };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const legacyScene = `import UIKit
|
|
24
|
+
import AppTrackingTransparency
|
|
25
|
+
class SceneDelegate {
|
|
26
|
+
private var isTrackingAuthorizationRequestScheduled = false
|
|
27
|
+
func sceneDidBecomeActive() {
|
|
28
|
+
if ATTrackingManager.trackingAuthorizationStatus == .notDetermined &&
|
|
29
|
+
!isTrackingAuthorizationRequestScheduled {
|
|
30
|
+
isTrackingAuthorizationRequestScheduled = true
|
|
31
|
+
|
|
32
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
|
|
33
|
+
self?.isTrackingAuthorizationRequestScheduled = false
|
|
34
|
+
|
|
35
|
+
guard UIApplication.shared.applicationState == .active,
|
|
36
|
+
ATTrackingManager.trackingAuthorizationStatus == .notDetermined else { return }
|
|
37
|
+
|
|
38
|
+
ATTrackingManager.requestTrackingAuthorization { _ in }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
keepOtherStartupCode()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
test('removes the known scene startup request with LF, CRLF and changed indentation', t => {
|
|
47
|
+
for (const source of [legacyScene, legacyScene.replace(/\n/g, '\r\n'), legacyScene.replace(/ /g, '\t')]) {
|
|
48
|
+
const f = fixture(t, { 'SceneDelegate.swift': source });
|
|
49
|
+
assert.equal(prepareIOSAdConsent(f.root, () => {}).length, 1);
|
|
50
|
+
assert.doesNotMatch(f.read('SceneDelegate.swift'), /ATTrackingManager|AppTrackingTransparency|isTrackingAuthorizationRequestScheduled/);
|
|
51
|
+
assert.match(f.read('SceneDelegate.swift'), /keepOtherStartupCode\(\)/);
|
|
52
|
+
assert.deepEqual(prepareIOSAdConsent(f.root, () => {}), [], 'Migration is idempotent');
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('rejects an AppDelegate ATT request even without a SceneDelegate', t => {
|
|
57
|
+
const source = 'ATTrackingManager\n .requestTrackingAuthorization { _ in }';
|
|
58
|
+
const f = fixture(t, { 'AppDelegate.swift': source });
|
|
59
|
+
assert.throws(() => prepareIOSAdConsent(f.root, () => {}), /AppDelegate.swift requests ATT/);
|
|
60
|
+
assert.equal(f.read('AppDelegate.swift'), source);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('checks nested app code and validates everything before migrating the scene', t => {
|
|
64
|
+
const f = fixture(t, {
|
|
65
|
+
'SceneDelegate.swift': legacyScene,
|
|
66
|
+
'Startup/Permissions.m': '[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:handler];',
|
|
67
|
+
});
|
|
68
|
+
assert.throws(() => prepareIOSAdConsent(f.root, () => {}), /Permissions.m requests ATT/);
|
|
69
|
+
assert.equal(f.read('SceneDelegate.swift'), legacyScene, 'No partial edits when validation fails');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('preserves custom native code and ignores commented ATT examples', t => {
|
|
73
|
+
const source = '// ATTrackingManager.requestTrackingAuthorization { _ in }\n/* ATTrackingManager.requestTrackingAuthorization */\nkeepOtherStartupCode()';
|
|
74
|
+
const f = fixture(t, { 'AppDelegate.swift': source });
|
|
75
|
+
assert.deepEqual(prepareIOSAdConsent(f.root, () => {}), []);
|
|
76
|
+
assert.equal(f.read('AppDelegate.swift'), source);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('installer ships the guard and generated before-build invokes it from the consuming app', t => {
|
|
80
|
+
const f = fixture(t, { 'SceneDelegate.swift': legacyScene });
|
|
81
|
+
fs.writeFileSync(path.join(f.root, 'package.json'), JSON.stringify({ name: 'consent-fixture', scripts: {} }));
|
|
82
|
+
fs.writeFileSync(path.join(f.root, 'capacitor.config.json'), JSON.stringify({ appId: 'fixture.app' }));
|
|
83
|
+
install({ projectRoot: f.root, copyAssets: false });
|
|
84
|
+
const beforeBuild = path.join(f.root, 'buildCodeplay/codeplayBeforeBuild.js');
|
|
85
|
+
const source = fs.readFileSync(beforeBuild, 'utf8').replace(/\r\n/g, '\n');
|
|
86
|
+
const start = source.indexOf('function updateIOSStartupForAdConsent() {');
|
|
87
|
+
const end = source.indexOf('\n\n\ntry {', start);
|
|
88
|
+
assert.ok(start >= 0 && end > start);
|
|
89
|
+
assert.ok(fs.existsSync(path.join(f.root, 'buildCodeplay/ios-ad-consent.cjs')));
|
|
90
|
+
vm.runInNewContext(source.slice(start, end) + '\nupdateIOSStartupForAdConsent();', {
|
|
91
|
+
require: createRequire(beforeBuild), process: { cwd: () => f.root },
|
|
92
|
+
});
|
|
93
|
+
assert.doesNotMatch(f.read('SceneDelegate.swift'), /requestTrackingAuthorization/);
|
|
94
|
+
assert.match(f.read('SceneDelegate.swift'), /keepOtherStartupCode\(\)/);
|
|
95
|
+
fs.writeFileSync(path.join(f.root, 'ios/App/App/AppDelegate.swift'), 'ATTrackingManager.requestTrackingAuthorization { _ in }');
|
|
96
|
+
assert.throws(() => vm.runInNewContext(source.slice(start, end) + '\nupdateIOSStartupForAdConsent();', {
|
|
97
|
+
require: createRequire(beforeBuild), process: { cwd: () => f.root },
|
|
98
|
+
}), /AppDelegate.swift requests ATT/);
|
|
99
|
+
});
|
|
@@ -85,6 +85,10 @@ test('Vite selects one store/provider for object and array aliases', async () =>
|
|
|
85
85
|
assert.equal(config.define['import.meta.env.VITE_RUADS_ENABLED'], JSON.stringify(['4', '10'].includes(id)));
|
|
86
86
|
assert.equal(selected, ['4', '10'].includes(id) ? path.resolve(f.root, 'src/js/Ads/vk-ads-1.10/vk-ads.js') : '/fixture/admob.js');
|
|
87
87
|
assert.equal(config.define.fixture, 'true');
|
|
88
|
+
const filter = config.plugins.find(plugin => plugin.name === 'codeplay-store-admob-config');
|
|
89
|
+
assert.ok(filter);
|
|
90
|
+
const filtered = filter.transform('{"androidAppId":"ca-app-pub-fixture"}', '/src/js/Ads/admob-ad-configuration-nextgen.json');
|
|
91
|
+
assert.equal(filtered === null, !['4', '10'].includes(id));
|
|
88
92
|
}
|
|
89
93
|
f.write('capacitor.config.json', { plugins: { AdMob: { ADMOB_ENABLED: false } } });
|
|
90
94
|
process.env.VITE_STORE_ID = '1';
|
|
@@ -101,6 +105,20 @@ test('Vite selects one store/provider for object and array aliases', async () =>
|
|
|
101
105
|
}
|
|
102
106
|
});
|
|
103
107
|
|
|
108
|
+
test('existing generated Vite wrapper gains AdMob ID filtering without repeated changes', () => {
|
|
109
|
+
const f = fixture();
|
|
110
|
+
syncRuAdsSetup(f.root, { runtimeRoot });
|
|
111
|
+
const file = path.join(f.root, 'vite.config.mjs');
|
|
112
|
+
const current = fs.readFileSync(file, 'utf8');
|
|
113
|
+
const old = current.replace('plugins: [...(base.plugins || []), ruAdsBuild.admobConfigPlugin(provider)], ', '');
|
|
114
|
+
assert.notEqual(old, current);
|
|
115
|
+
fs.writeFileSync(file, old);
|
|
116
|
+
syncRuAdsSetup(f.root, { runtimeRoot });
|
|
117
|
+
assert.equal(fs.readFileSync(file, 'utf8'), current);
|
|
118
|
+
syncRuAdsSetup(f.root, { runtimeRoot });
|
|
119
|
+
assert.equal(fs.readFileSync(file, 'utf8'), current);
|
|
120
|
+
});
|
|
121
|
+
|
|
104
122
|
test('installer distributes all RuStore helpers and preserves release credentials', () => {
|
|
105
123
|
const f = fixture();
|
|
106
124
|
f.write('buildCodeplay/release-sync.config.json', { token: 'consumer-owned' });
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { syncAndroidAdmobPolicy, withNativeAdProvider, admobConfigPlugin } = require('../files/buildCodeplay/ruads.cjs');
|
|
6
|
+
|
|
7
|
+
function fixture(enabled = true) {
|
|
8
|
+
const temp = path.resolve(__dirname, '../agent-temp');
|
|
9
|
+
fs.mkdirSync(temp, { recursive: true });
|
|
10
|
+
const root = fs.mkdtempSync(path.join(temp, 'admob-policy-'));
|
|
11
|
+
const config = {
|
|
12
|
+
plugins: { AdMob: { ADMOB_ENABLED: enabled, APP_ID_ANDROID: 'ca-app-pub-restored' },
|
|
13
|
+
RuAds: { VK_ADS_ENABLED: true, STORE_IDS: [4, 10] }, FirebaseAnalytics: {} },
|
|
14
|
+
};
|
|
15
|
+
const manifest = `<?xml version="1.0"?>
|
|
16
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
17
|
+
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
|
|
18
|
+
<application>
|
|
19
|
+
<meta-data android:value="ca-app-pub-example" android:name="com.google.android.gms.ads.APPLICATION_ID" />
|
|
20
|
+
<meta-data android:name='com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING' android:value='true'></meta-data>
|
|
21
|
+
<activity android:name="com.google.android.gms.ads.AdActivity"><intent-filter /></activity>
|
|
22
|
+
<provider android:name="com.google.android.gms.ads.MobileAdsInitProvider" />
|
|
23
|
+
<activity android:name="com.my.target.ads.MyTargetActivity" />
|
|
24
|
+
<meta-data android:name="firebase_analytics_collection_enabled" android:value="true" />
|
|
25
|
+
</application>
|
|
26
|
+
</manifest>
|
|
27
|
+
`;
|
|
28
|
+
const write = (name, value) => {
|
|
29
|
+
const file = path.join(root, name);
|
|
30
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
31
|
+
fs.writeFileSync(file, typeof value === 'string' ? value : JSON.stringify(value));
|
|
32
|
+
};
|
|
33
|
+
write('capacitor.config.json', config);
|
|
34
|
+
write('package.json', { dependencies: {
|
|
35
|
+
'capacitor-admob-nextgen': '1', 'capacitor-codeplay-rustore-ads': '1', '@capacitor/app': '1',
|
|
36
|
+
} });
|
|
37
|
+
write('android/app/build.gradle', "apply plugin: 'com.android.application'\n");
|
|
38
|
+
write('android/app/src/main/AndroidManifest.xml', manifest);
|
|
39
|
+
write('android/app/src/main/assets/capacitor.config.json', config);
|
|
40
|
+
return { root, write, manifest, read: name => fs.readFileSync(path.join(root, name), 'utf8') };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (const storeId of [4, 10]) {
|
|
44
|
+
test(`store ${storeId}: clean synced config, stale manifest and SDKs; repeat safely`, () => {
|
|
45
|
+
const f = fixture();
|
|
46
|
+
const originalConfig = f.read('capacitor.config.json');
|
|
47
|
+
assert.equal(withNativeAdProvider(f.root, storeId, 'android', provider => {
|
|
48
|
+
assert.equal(provider, 'vk');
|
|
49
|
+
const scoped = JSON.parse(f.read('capacitor.config.json'));
|
|
50
|
+
assert.equal(scoped.plugins.AdMob, undefined);
|
|
51
|
+
assert.ok(scoped.android.includePlugins.includes('capacitor-codeplay-rustore-ads'));
|
|
52
|
+
assert.ok(!scoped.android.includePlugins.includes('capacitor-admob-nextgen'));
|
|
53
|
+
// Simulate cap sync copying the scoped config and retaining old app entries.
|
|
54
|
+
f.write('android/app/src/main/assets/capacitor.config.json', scoped);
|
|
55
|
+
return 'synced';
|
|
56
|
+
}), 'synced');
|
|
57
|
+
assert.equal(f.read('capacitor.config.json'), originalConfig);
|
|
58
|
+
const manifest = f.read('android/app/src/main/AndroidManifest.xml');
|
|
59
|
+
assert.doesNotMatch(manifest, /com\.google\.android\.gms\.ads\.|ca-app-pub-/);
|
|
60
|
+
assert.match(manifest, /MyTargetActivity/);
|
|
61
|
+
assert.match(manifest, /firebase_analytics_collection_enabled/);
|
|
62
|
+
assert.match(manifest, /permission.AD_ID/);
|
|
63
|
+
const gradle = f.read('android/app/build.gradle');
|
|
64
|
+
assert.match(gradle, /module: 'play-services-ads'/);
|
|
65
|
+
assert.doesNotMatch(gradle, /module: 'play-services-ads-identifier'/);
|
|
66
|
+
assert.equal(syncAndroidAdmobPolicy(f.root, storeId), false);
|
|
67
|
+
|
|
68
|
+
// A later AdMob store must restore metadata without manually reseeding it.
|
|
69
|
+
assert.equal(syncAndroidAdmobPolicy(f.root, 1), true);
|
|
70
|
+
assert.doesNotMatch(f.read('android/app/build.gradle'), /CODEPLAY EXCLUDE ADMOB/);
|
|
71
|
+
assert.match(f.read('android/app/src/main/AndroidManifest.xml'), /ca-app-pub-restored/);
|
|
72
|
+
assert.match(f.read('android/app/src/main/AndroidManifest.xml'), /OPTIMIZE_AD_LOADING/);
|
|
73
|
+
const restored = f.read('android/app/src/main/AndroidManifest.xml');
|
|
74
|
+
assert.equal(syncAndroidAdmobPolicy(f.root, 1), false);
|
|
75
|
+
assert.equal(f.read('android/app/src/main/AndroidManifest.xml'), restored);
|
|
76
|
+
withNativeAdProvider(f.root, 1, 'android', provider => {
|
|
77
|
+
assert.equal(provider, 'admob');
|
|
78
|
+
const scoped = JSON.parse(f.read('capacitor.config.json'));
|
|
79
|
+
assert.ok(scoped.android.includePlugins.includes('capacitor-admob-nextgen'));
|
|
80
|
+
assert.ok(!scoped.android.includePlugins.includes('capacitor-codeplay-rustore-ads'));
|
|
81
|
+
assert.equal(scoped.plugins.AdMob.APP_ID_ANDROID, 'ca-app-pub-restored');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
test('globally disabled AdMob cleans stores outside Huawei/RuStore', () => {
|
|
87
|
+
const f = fixture(false);
|
|
88
|
+
withNativeAdProvider(f.root, 3, 'android', provider => assert.equal(provider, 'none'));
|
|
89
|
+
assert.doesNotMatch(f.read('android/app/src/main/AndroidManifest.xml'), /com\.google\.android\.gms\.ads\./);
|
|
90
|
+
assert.equal(JSON.parse(f.read('android/app/src/main/assets/capacitor.config.json')).plugins.AdMob, undefined);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('sync failure restores root settings; Android cleanup does not affect iOS', () => {
|
|
94
|
+
const f = fixture();
|
|
95
|
+
const original = f.read('capacitor.config.json');
|
|
96
|
+
assert.throws(() => withNativeAdProvider(f.root, 10, 'android', () => { throw new Error('sync failed'); }), /sync failed/);
|
|
97
|
+
assert.equal(f.read('capacitor.config.json'), original);
|
|
98
|
+
assert.equal(syncAndroidAdmobPolicy(f.root, 10, 'ios'), false);
|
|
99
|
+
assert.equal(f.read('android/app/src/main/AndroidManifest.xml'), f.manifest);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('non-AdMob web bundles omit live/test IDs while preserving shared IAP configuration', () => {
|
|
103
|
+
const original = { IAP: { samsung: true }, androidAppId: 'ca-app-pub-app',
|
|
104
|
+
android: { bannerid: 'ca-app-pub-live' }, testid: { bannerid: ['ca-app-pub-test'] },
|
|
105
|
+
config: { bannerEnabled: true, interstitialEnabled: true } };
|
|
106
|
+
const source = JSON.stringify(original);
|
|
107
|
+
const id = '/src/js/Ads/admob-ad-configuration-nextgen.json';
|
|
108
|
+
for (const provider of ['vk', 'none']) {
|
|
109
|
+
const result = JSON.parse(admobConfigPlugin(provider).transform(source, id).code);
|
|
110
|
+
assert.doesNotMatch(JSON.stringify(result), /ca-app-pub-/);
|
|
111
|
+
assert.deepEqual(result.IAP, original.IAP);
|
|
112
|
+
assert.equal(result.config.bannerEnabled, false);
|
|
113
|
+
}
|
|
114
|
+
assert.equal(admobConfigPlugin('admob').transform(source, id), null);
|
|
115
|
+
assert.equal(admobConfigPlugin('vk').transform(source, '/vk-ad-configuration.json'), null);
|
|
116
|
+
assert.equal(JSON.stringify(original), source);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('AdMob restoration uses configured app ID and preserves child-directed AD_ID exclusion', () => {
|
|
120
|
+
const f = fixture();
|
|
121
|
+
f.write('src/js/Ads/admob-ad-configuration-nextgen.json', {
|
|
122
|
+
androidAppId: 'ca-app-pub-preferred', config: { isKidsApp: true },
|
|
123
|
+
});
|
|
124
|
+
f.write('android/app/src/main/AndroidManifest.xml', '<manifest><application></application></manifest>');
|
|
125
|
+
syncAndroidAdmobPolicy(f.root, 1);
|
|
126
|
+
const restored = f.read('android/app/src/main/AndroidManifest.xml');
|
|
127
|
+
assert.match(restored, /ca-app-pub-preferred/);
|
|
128
|
+
assert.doesNotMatch(restored, /permission.AD_ID/);
|
|
129
|
+
assert.equal(syncAndroidAdmobPolicy(f.root, 1), false);
|
|
130
|
+
});
|