@webority/mobile-tools 0.155.1 → 0.157.0

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/README.md CHANGED
@@ -45,11 +45,11 @@ npx mobile-tools prebuild --same-env [--platform android|ios]
45
45
  - When another environment's icon set exists but this one's does not, prebuild fails, so a build never ships the wrong icon.
46
46
  - Copies `<firebasePlistDir>/GoogleService-Info.<Env>.plist` to `ios/<name>/GoogleService-Info.plist`. Without that file for the environment it fails when the app depends on `@react-native-firebase/app` (the Crashlytics build phase needs it), and otherwise removes the copy.
47
47
  - **Firebase on Android**: an app that depends on `@react-native-firebase/app` fails without `android/app/google-services.json`, whose absence would otherwise stop the Gradle build later with a less direct error.
48
- - **Over-the-air updates**: OTA is on when the settings carry `OTA_UPDATE_BASE_URL` and the platform's component id (`OTA_ANDROID_COMPONENT_ID`, `OTA_IOS_COMPONENT_ID`). Otherwise OTA is off for the environment.
48
+ - **Over-the-air updates**: OTA is on when the settings carry `OTA_UPDATE_BASE_URL` and the platform's component public id (`OTA_ANDROID_COMPONENT_PUBLIC_ID`, `OTA_IOS_COMPONENT_PUBLIC_ID`). Otherwise OTA is off for the environment.
49
49
  - Writes `android/app/src/<flavor>/AndroidManifest.xml` for the environment's flavor, with the `expo.modules.updates.*` meta-data, and `ios/<name>/Supporting/Expo.plist` as a whole plist document. Both are git-ignored, so neither is tracked.
50
- - With OTA on, the manifest URL `<OTA_UPDATE_BASE_URL>/ota/manifest/<OTA_PROJECT_ID>/<component id>/<environment>`, the runtime version `VERSION_INTERNAL`, check on launch `ALWAYS`, launch wait 0, and the code-signing certificate with the key id read from it and `alg` `rsa-v1_5-sha256`.
50
+ - With OTA on, the manifest URL `<OTA_UPDATE_BASE_URL>/ota/manifest/<OTA_PROJECT_PUBLIC_ID>/<component public id>/<environment>`, the runtime version `VERSION_INTERNAL`, check on launch `ALWAYS`, launch wait 0, and the code-signing certificate with the key id read from it and `alg` `rsa-v1_5-sha256`.
51
51
  - With OTA off, the Android manifest holds only `expo.modules.updates.ENABLED` `false`, and Expo.plist holds only `EXUpdatesEnabled` `<false/>`.
52
- - `OTA_CODE_SIGNING_CERT` names the update server's PEM certificate, relative to the app folder. It is required, because the server signs every manifest and an app without the certificate cannot verify one. A missing `OTA_PROJECT_ID` also fails.
52
+ - `OTA_CODE_SIGNING_CERT` names the update server's PEM certificate, relative to the app folder. It is required, because the server signs every manifest and an app without the certificate cannot verify one. A missing or malformed `OTA_PROJECT_PUBLIC_ID` also fails; the public ids are GUIDs, written lowercase. A setting that still carries a removed key (`OTA_PROJECT_ID`, `OTA_ANDROID_COMPONENT_ID`, `OTA_IOS_COMPONENT_ID`) fails, naming its replacement.
53
53
  - An app without environment flavors is refused: the flavor manifest is the only place these settings go.
54
54
  - Without `--platform`, it writes the files of every platform folder the app has.
55
55
  - `--same-env` recompiles the environment last compiled, which refreshes the build stamp.
@@ -1,9 +1,11 @@
1
1
  import type { Environment } from "./config.js";
2
2
  export type OtaPlatform = "android" | "ios";
3
- /** The compiled settings key holding each platform's OTA component id on the update server. */
3
+ /** The compiled settings key holding each platform's OTA component public id on the update server. */
4
4
  export declare const COMPONENT_KEY: Record<OtaPlatform, string>;
5
- /** A platform's component id from the settings; a missing or non-numeric id fails, naming the key. */
6
- export declare const componentIdFor: (settings: Record<string, unknown>, platform: OtaPlatform) => string;
5
+ /** A public id from the settings, lowercased; a missing or malformed id fails, naming the key. */
6
+ export declare function publicIdOf(settings: Record<string, unknown>, key: string, what: string): string;
7
+ /** A platform's component public id from the settings; a missing or malformed id fails, naming the key. */
8
+ export declare const componentPublicIdFor: (settings: Record<string, unknown>, platform: OtaPlatform) => string;
7
9
  /**
8
10
  * The code-signing key id an app's certificate carries: its common name, which the update server
9
11
  * holds the matching private key under. A name that is not a key id (the retired shared
@@ -18,9 +20,10 @@ export interface OtaNativeSettings {
18
20
  }
19
21
  /**
20
22
  * The expo-updates settings for one platform, or undefined when the app has no OTA there: no
21
- * `OTA_UPDATE_BASE_URL`, or no component id for this platform. Once the base URL is set, a missing
22
- * project id or signing certificate fails, because a binary that cannot verify updates never
23
- * applies one.
23
+ * `OTA_UPDATE_BASE_URL`, or no component public id for this platform. Once the base URL is set, a
24
+ * missing project public id or signing certificate fails, because a binary that cannot verify
25
+ * updates never applies one. A setting the update server no longer reads fails first, naming its
26
+ * replacement.
24
27
  */
25
28
  export declare const otaNativeSettings: (appRoot: string, settings: Record<string, unknown>, env: Environment, platform: OtaPlatform, otaTest: boolean) => OtaNativeSettings | undefined;
26
29
  /** The Android meta-data expo-updates reads, in the order a new entry is written. */
package/lib/otaNative.js CHANGED
@@ -1 +1 @@
1
- import{X509Certificate}from"node:crypto";import{existsSync,readFileSync}from"node:fs";import path from"node:path";import{fail}from"./output.js";export const COMPONENT_KEY={android:"OTA_ANDROID_COMPONENT_ID",ios:"OTA_IOS_COMPONENT_ID"};const CODE_SIGNING_ALG="rsa-v1_5-sha256",KEY_ID=/^[a-z][a-z0-9]*$/,WHOLE_NUMBER=/^[1-9][0-9]*$/,isSet=e=>null!=e&&""!==e;export const componentIdFor=(e,t)=>{const i=COMPONENT_KEY[t],n=e[i];return isSet(n)?WHOLE_NUMBER.test(String(n))?String(n):fail("appConfigInvalid",`${i} must be a positive whole number, not ${JSON.stringify(n)}`):fail("appConfigInvalid",`appsettings has no ${i}: the ${t} app has no OTA component to publish to`)};export const codeSigningKeyIdOf=(e,t)=>{let i;try{i=new X509Certificate(e).subject}catch{return fail("appConfigInvalid",`${t} is not a readable X.509 certificate`)}const n=i.split("\n").filter(e=>e.startsWith("CN=")),[a]=n,o=1===n.length&&void 0!==a?a.slice(3):"";return o.endsWith(" OTA Updates")?fail("appConfigInvalid",`${t} is the shared OTA certificate (CN=${o}), which is retired for this app: get the product's own certificate with \`bash scripts/ota-signing-key.sh cert <keyid> --out certs/ota-code-signing-cert.pem\` in the repository that owns the OTA signing keys`):KEY_ID.test(o)?o:fail("appConfigInvalid",`${t} has common name ${JSON.stringify(o)}, which is not a signing key id (a lowercase name, for example acme)`)};export const otaNativeSettings=(e,t,i,n,a)=>{const o=t.OTA_UPDATE_BASE_URL;if(!isSet(o)||!isSet(t[COMPONENT_KEY[n]]))return;const s=componentIdFor(t,n),r=t.OTA_PROJECT_ID;if(!isSet(r)||!WHOLE_NUMBER.test(String(r)))return fail("appConfigInvalid",`OTA_PROJECT_ID must be the update server's project id (a positive whole number), not ${JSON.stringify(r)}`);const p=t.OTA_CODE_SIGNING_CERT;if("string"!=typeof p||""===p.trim())return fail("appConfigInvalid","OTA_CODE_SIGNING_CERT must name the PEM certificate file, relative to the app folder");const d=path.join(e,p);if(!existsSync(d))return fail("appConfigInvalid",`OTA_CODE_SIGNING_CERT ${p} not found in ${e}`);const c=readFileSync(d,"utf8").replace(/\r\n/g,"\n").trim();return c.startsWith("-----BEGIN CERTIFICATE-----")?{updateUrl:`${String(o).replace(/\/+$/,"")}/ota/manifest/${r}/${s}/${i}`,runtimeVersion:a?`${String(t.VERSION_INTERNAL)}-otatest`:String(t.VERSION_INTERNAL),certificate:c,keyId:codeSigningKeyIdOf(c,p)}:fail("appConfigInvalid",`${p} is not a PEM certificate`)};const escapeXml=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");export const androidOtaMetaData=e=>[["expo.modules.updates.ENABLED","true"],["expo.modules.updates.EXPO_UPDATE_URL",e.updateUrl],["expo.modules.updates.EXPO_RUNTIME_VERSION",e.runtimeVersion],["expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH","ALWAYS"],["expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS","0"],["expo.modules.updates.CODE_SIGNING_CERTIFICATE",e.certificate],["expo.modules.updates.CODE_SIGNING_METADATA",JSON.stringify({keyid:e.keyId,alg:CODE_SIGNING_ALG})]];export const androidOtaManifest=e=>'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Written by mobile-tools prebuild for this flavor\'s environment. Not tracked: run prebuild to change it. --\x3e\n<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n <application>\n'+(e?androidOtaMetaData(e):[["expo.modules.updates.ENABLED","false"]]).map(([e,t])=>` <meta-data android:name="${e}" android:value="${escapeXml(t).replace(/\n/g,"&#10;")}" />\n`).join("")+" </application>\n</manifest>\n";export const iosOtaPlistKeys=e=>[["EXUpdatesEnabled",!0],["EXUpdatesURL",e.updateUrl],["EXUpdatesRuntimeVersion",e.runtimeVersion],["EXUpdatesCheckOnLaunch","ALWAYS"],["EXUpdatesLaunchWaitMs",0],["EXUpdatesCodeSigningCertificate",e.certificate],["EXUpdatesCodeSigningMetadata",{keyid:e.keyId,alg:CODE_SIGNING_ALG}]];const plistValue=(e,t,i)=>{if("boolean"==typeof e)return e?"<true/>":"<false/>";if("number"==typeof e)return`<integer>${e}</integer>`;if("string"==typeof e)return`<string>${escapeXml(e).replace(/\n/g,i)}</string>`;const n=`${t}${t.includes("\t")?"\t":" "}`,a=Object.entries(e).map(([e,t])=>`${n}<key>${escapeXml(e)}</key>${i}${n}<string>${escapeXml(t)}</string>`).join(i);return`<dict>${i}${a}${i}${t}</dict>`};export const expoPlist=e=>'<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n'+(e?iosOtaPlistKeys(e):[["EXUpdatesEnabled",!1]]).map(([e,t])=>`\t<key>${escapeXml(e)}</key>\n\t${plistValue(t,"\t","\n")}\n`).join("")+"</dict>\n</plist>\n";
1
+ import{X509Certificate}from"node:crypto";import{existsSync,readFileSync}from"node:fs";import path from"node:path";import{fail}from"./output.js";export const COMPONENT_KEY={android:"OTA_ANDROID_COMPONENT_PUBLIC_ID",ios:"OTA_IOS_COMPONENT_PUBLIC_ID"};const CODE_SIGNING_ALG="rsa-v1_5-sha256",KEY_ID=/^[a-z][a-z0-9]*$/,PUBLIC_ID=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,RETIRED_KEYS={OTA_PROJECT_ID:"OTA_PROJECT_PUBLIC_ID",OTA_ANDROID_COMPONENT_ID:"OTA_ANDROID_COMPONENT_PUBLIC_ID",OTA_IOS_COMPONENT_ID:"OTA_IOS_COMPONENT_PUBLIC_ID"},isSet=e=>null!=e&&""!==e;export function publicIdOf(e,t,i){const n=e[t];return isSet(n)?PUBLIC_ID.test(String(n))?String(n).toLowerCase():fail("appConfigInvalid",`${t} must be the update server's public id (a GUID such as 3f2b8c1e-0a4d-4e6b-9c2f-7d1e5a9b0c3d), not ${JSON.stringify(n)}`):fail("appConfigInvalid",`appsettings has no ${t}: ${i}`)}export const componentPublicIdFor=(e,t)=>publicIdOf(e,COMPONENT_KEY[t],`the ${t} app has no OTA component to publish to`);export const codeSigningKeyIdOf=(e,t)=>{let i;try{i=new X509Certificate(e).subject}catch{return fail("appConfigInvalid",`${t} is not a readable X.509 certificate`)}const n=i.split("\n").filter(e=>e.startsWith("CN=")),[a]=n,s=1===n.length&&void 0!==a?a.slice(3):"";return s.endsWith(" OTA Updates")?fail("appConfigInvalid",`${t} is the shared OTA certificate (CN=${s}), which is retired for this app: get the product's own certificate with \`bash scripts/ota-signing-key.sh cert <keyid> --out certs/ota-code-signing-cert.pem\` in the repository that owns the OTA signing keys`):KEY_ID.test(s)?s:fail("appConfigInvalid",`${t} has common name ${JSON.stringify(s)}, which is not a signing key id (a lowercase name, for example acme)`)};export const otaNativeSettings=(e,t,i,n,a)=>{for(const[e,i]of Object.entries(RETIRED_KEYS))if(isSet(t[e]))return fail("appConfigInvalid",`${e} is removed: the update server now addresses apps by public id, so set ${i} (a GUID) instead`);const s=t.OTA_UPDATE_BASE_URL;if(!isSet(s)||!isSet(t[COMPONENT_KEY[n]]))return;const o=componentPublicIdFor(t,n),r=publicIdOf(t,"OTA_PROJECT_PUBLIC_ID","OTA updates need the update server's project public id"),p=t.OTA_CODE_SIGNING_CERT;if("string"!=typeof p||""===p.trim())return fail("appConfigInvalid","OTA_CODE_SIGNING_CERT must name the PEM certificate file, relative to the app folder");const d=path.join(e,p);if(!existsSync(d))return fail("appConfigInvalid",`OTA_CODE_SIGNING_CERT ${p} not found in ${e}`);const c=readFileSync(d,"utf8").replace(/\r\n/g,"\n").trim();return c.startsWith("-----BEGIN CERTIFICATE-----")?{updateUrl:`${String(s).replace(/\/+$/,"")}/ota/manifest/${r}/${o}/${i}`,runtimeVersion:a?`${String(t.VERSION_INTERNAL)}-otatest`:String(t.VERSION_INTERNAL),certificate:c,keyId:codeSigningKeyIdOf(c,p)}:fail("appConfigInvalid",`${p} is not a PEM certificate`)};const escapeXml=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");export const androidOtaMetaData=e=>[["expo.modules.updates.ENABLED","true"],["expo.modules.updates.EXPO_UPDATE_URL",e.updateUrl],["expo.modules.updates.EXPO_RUNTIME_VERSION",e.runtimeVersion],["expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH","ALWAYS"],["expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS","0"],["expo.modules.updates.CODE_SIGNING_CERTIFICATE",e.certificate],["expo.modules.updates.CODE_SIGNING_METADATA",JSON.stringify({keyid:e.keyId,alg:CODE_SIGNING_ALG})]];export const androidOtaManifest=e=>'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Written by mobile-tools prebuild for this flavor\'s environment. Not tracked: run prebuild to change it. --\x3e\n<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n <application>\n'+(e?androidOtaMetaData(e):[["expo.modules.updates.ENABLED","false"]]).map(([e,t])=>` <meta-data android:name="${e}" android:value="${escapeXml(t).replace(/\n/g,"&#10;")}" />\n`).join("")+" </application>\n</manifest>\n";export const iosOtaPlistKeys=e=>[["EXUpdatesEnabled",!0],["EXUpdatesURL",e.updateUrl],["EXUpdatesRuntimeVersion",e.runtimeVersion],["EXUpdatesCheckOnLaunch","ALWAYS"],["EXUpdatesLaunchWaitMs",0],["EXUpdatesCodeSigningCertificate",e.certificate],["EXUpdatesCodeSigningMetadata",{keyid:e.keyId,alg:CODE_SIGNING_ALG}]];const plistValue=(e,t,i)=>{if("boolean"==typeof e)return e?"<true/>":"<false/>";if("number"==typeof e)return`<integer>${e}</integer>`;if("string"==typeof e)return`<string>${escapeXml(e).replace(/\n/g,i)}</string>`;const n=`${t}${t.includes("\t")?"\t":" "}`,a=Object.entries(e).map(([e,t])=>`${n}<key>${escapeXml(e)}</key>${i}${n}<string>${escapeXml(t)}</string>`).join(i);return`<dict>${i}${a}${i}${t}</dict>`};export const expoPlist=e=>'<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n'+(e?iosOtaPlistKeys(e):[["EXUpdatesEnabled",!1]]).map(([e,t])=>`\t<key>${escapeXml(e)}</key>\n\t${plistValue(t,"\t","\n")}\n`).join("")+"</dict>\n</plist>\n";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/mobile-tools",
3
- "version": "0.155.1",
3
+ "version": "0.157.0",
4
4
  "description": "Dev-time CLI for Webority React Native apps: one prebuild, a dependency guard, a device-aware run and per-environment launcher icons, the same on Windows and macOS.",
5
5
  "keywords": [
6
6
  "react-native",