2026-10-20 15:35:58 +08:00
|
|
|
const { internal } = require('../config/environment.cjs');
|
|
|
|
|
|
|
|
|
|
function assertInstallableConfig(config) {
|
|
|
|
|
const variant = config.extra?.environment;
|
|
|
|
|
if (!['dev', 'prod'].includes(variant)) throw Error('Explicit App environment required');
|
|
|
|
|
if (!config.updates?.enabled || !config.updates.codeSigningCertificate) throw Error('Installable App requires signed updates');
|
|
|
|
|
const url = new URL(config.updates.url);
|
|
|
|
|
// Loopback is valid for local preview, never for an APK delivered to phones.
|
2026-10-29 17:27:46 +08:00
|
|
|
internal(url.origin, false, variant === 'prod');
|
2026-10-20 15:35:58 +08:00
|
|
|
if (url.pathname !== `/updates/${variant}` || url.search || url.hash) throw Error('Update channel must match App environment');
|
|
|
|
|
if (config.updates.codeSigningMetadata?.keyid !== variant) throw Error('Update signing key must match App environment');
|
|
|
|
|
if (config.android?.package !== (variant === 'dev' ? 'cn.cmvr.wms.dev' : 'cn.cmvr.wms')) throw Error('App package/environment mismatch');
|
|
|
|
|
return url.toString();
|
|
|
|
|
}
|
|
|
|
|
module.exports = { assertInstallableConfig };
|
|
|
|
|
if (require.main === module) {
|
|
|
|
|
const config = require('../app.config.js')();
|
|
|
|
|
console.log(`Installable ${config.extra.environment} App: ${assertInstallableConfig(config)}`);
|
|
|
|
|
}
|