Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update core model build scripts (#2159)
Leendert de Borstb133a856c2d0
diff --git a/core/models/README.md b/core/models/README.mdindex fef432f28..666388f76 100644--- a/core/models/README.md+++ b/core/models/README.md@@ -9,7 +9,7 @@ This package performs two key functions:### 1. TypeScript Distribution (Linked as Source)TypeScript models are consumed as the `@aliasvault/models` package:- **Browser Extension**: linked as source through `@aliasvault/models` (see `core/client`)-- **Mobile App**: TODO: migrate to linked source via `@aliasvault/models` (currently still copied to `apps/mobile-app/utils/dist/core/models` for legacy reasons)+- **Mobile App**: linked as source through `@aliasvault/models` (a `file:` dependency; `metro.config.js` watches `core/`)### 2. Native Code Generation (Transformed)Automatically generates platform-specific models from TypeScript sources:@@ -26,6 +26,7 @@ Automatically generates platform-specific models from TypeScript sources:|-----------|-----------------|-------|| `scripts/generate-vault-table-registry.cjs` | `src/vault/VaultTableRegistry.ts` | the Rust codec's datamodel registry, the C# `VaultTableRegistry`, and `VaultDataBucketCategory` (C#, Swift, Kotlin) || `scripts/generate-key-vocabulary.cjs` | the `VOCABULARIES` table inside the script | `UnlockMethodType`, `ManifestKeyType`, `VaultKeyAlgorithm` |+| `scripts/generate-app-defaults.cjs` | `src/defaults/AppDefaults.ts` | the Swift and Kotlin `AppInfo` (minimum server version, default URLs) |The key vocabulary is the set of tokens naming how a vault key is protected, which unlock method encrypts auser's Account Key, how a manifest's VEK reaches a given user, and which algorithm a piece of key ciphertextdiff --git a/core/models/build.sh b/core/models/build.shindex 02a609d4e..534d7942c 100755--- a/core/models/build.sh+++ b/core/models/build.sh@@ -3,12 +3,6 @@set -e # Stop on errorset -u # Treat unset variables as errors-# Define output targets for models-# TODO: remove this whole copy logic once the mobile app is migrated to the new core-TARGETS=(- "../../apps/mobile-app/utils/dist/core/models"-)-# Build and distribute modelspackage_name="models"package_path="."@@ -38,35 +32,7 @@ node scripts/generate-password-defaults.cjsecho "π Generating language reference (C#)..."node scripts/generate-languages.cjs-dist_path="dist"-files_to_copy=("webapi" "vault" "defaults" "metadata" "icons" "identity")--for target in "${TARGETS[@]}"; do- echo "π Copying $package_name β $target"-- # Remove any existing files in the target directory- rm -rf "$target"-- # (Re)create the target directory- mkdir -p "$target"-- # Copy specific build outputs (files and folders)- for file in "${files_to_copy[@]}"; do- cp -R "$dist_path/$file" "$target/"- done-- # Write README- cat > "$target/README.md" <<EOF-# β οΈ Auto-Generated Files--This folder contains the output of the core \`$package_name\` module from the \`/core\` directory in the AliasVault project.--**Do not edit any of these files manually.**--To make changes:-1. Update the source files in the \`/core/models/src\` directory-2. Run the \`build.sh\` script in the module directory to regenerate the outputs and copy them here.-EOF-done+echo "π Generating app defaults (Swift, Kotlin)..."+node scripts/generate-app-defaults.cjs-echo "β Models build and copy completed."\ No newline at end of file+echo "β Models build completed. TypeScript clients link this package as source (@aliasvault/models)."\ No newline at end of filediff --git a/core/models/scripts/generate-app-defaults.cjs b/core/models/scripts/generate-app-defaults.cjsnew file mode 100644index 000000000..ba1afc7aa--- /dev/null+++ b/core/models/scripts/generate-app-defaults.cjs@@ -0,0 +1,137 @@+#!/usr/bin/env node+/**+ * Generates the client-wide connection defaults (minimum server version, default URLs) for the native mobile+ * platforms.+ *+ * Input: core/models/src/defaults/AppDefaults.ts+ * Outputs:+ * - apps/mobile-app/ios/VaultStoreKit/AppInfo.swift (Swift)+ * - apps/mobile-app/android/app/src/main/java/net/aliasvault/app/utils/AppInfo.kt (Kotlin)+ *+ * TypeScript clients import the constants directly from `@aliasvault/models/defaults`.+ */++const fs = require('fs');+const path = require('path');++const REPO_ROOT = path.join(__dirname, '../../..');+const TS_SOURCE_REL = 'core/models/src/defaults/AppDefaults.ts';+const TS_SOURCE = path.join(REPO_ROOT, TS_SOURCE_REL);+const SWIFT_OUTPUT = path.join(REPO_ROOT, 'apps/mobile-app/ios/VaultStoreKit/AppInfo.swift');+const KOTLIN_OUTPUT = path.join(REPO_ROOT, 'apps/mobile-app/android/app/src/main/java/net/aliasvault/app/utils/AppInfo.kt');++/**+ * Parse the `export const NAME = '...';` lines (each with its preceding JSDoc comment) out of the TypeScript+ * source, preserving order.+ */+function parseConstants(source) {+ const constants = [];+ const lines = source.split(/\r?\n/);+ let docLines = [];+ let inDoc = false;++ for (const line of lines) {+ const trimmed = line.trim();+ if (trimmed.startsWith('/**')) {+ inDoc = true;+ docLines = [];+ const inline = trimmed.replace(/^\/\*\*/, '').replace(/\*\/$/, '').trim();+ if (inline) {+ docLines.push(inline);+ }+ if (trimmed.endsWith('*/')) {+ inDoc = false;+ }+ continue;+ }+ if (inDoc) {+ if (trimmed.endsWith('*/')) {+ inDoc = false;+ } else {+ const text = trimmed.replace(/^\*\s?/, '');+ if (text) {+ docLines.push(text);+ }+ }+ continue;+ }++ const constMatch = line.match(/^\s*export const ([A-Z0-9_]+)\s*=\s*'([^']*)'\s*;/);+ if (constMatch) {+ constants.push({ name: constMatch[1], value: constMatch[2], doc: docLines.length > 0 ? docLines : [`${constMatch[1]}.`] });+ docLines = [];+ continue;+ }+ if (trimmed !== '') {+ docLines = [];+ }+ }++ if (constants.length === 0) {+ throw new Error(`No 'export const ... = '<string>';' constants found in ${TS_SOURCE_REL}`);+ }+ return constants;+}++/** Convert to camel case (MIN_SERVER_VERSION -> minServerVersion). */+function toCamelCase(name) {+ return name.toLowerCase().replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());+}++/** Escape a string for a Swift or Kotlin double-quoted literal. */+function quote(value) {+ return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\$/g, '\\$');+}++function generateSwift(constants) {+ const members = constants+ .map((c) => `${c.doc.map((line) => ` /// ${line}`).join('\n')}\n public static let ${toCamelCase(c.name)} = "${quote(c.value)}"`)+ .join('\n\n');++ return `// <auto-generated />+// This file is auto-generated from ${TS_SOURCE_REL}+// Do not edit this file directly. Run 'core/models/build.sh' (or+// 'node core/models/scripts/generate-app-defaults.cjs') to regenerate.++import Foundation++/// Client-wide connection defaults shared by every AliasVault client.+public enum AppInfo {+${members}+}+`;+}++function generateKotlin(constants) {+ const members = constants+ .map((c) => {+ const doc = c.doc.map((line) => ` * ${line}`).join('\n');+ return ` /**\n${doc}\n */\n const val ${c.name} = "${quote(c.value)}"`;+ })+ .join('\n\n');++ return `// <auto-generated />+// This file is auto-generated from ${TS_SOURCE_REL}+// Do not edit this file directly. Run 'core/models/build.sh' (or+// 'node core/models/scripts/generate-app-defaults.cjs') to regenerate.++package net.aliasvault.app.utils++/**+ * Client-wide connection defaults shared by every AliasVault client.+ */+object AppInfo {+${members}+}+`;+}++function main() {+ const constants = parseConstants(fs.readFileSync(TS_SOURCE, 'utf8'));+ fs.writeFileSync(SWIFT_OUTPUT, generateSwift(constants));+ fs.writeFileSync(KOTLIN_OUTPUT, generateKotlin(constants));+ console.log(` β Generated ${path.relative(REPO_ROOT, SWIFT_OUTPUT)}`);+ console.log(` β Generated ${path.relative(REPO_ROOT, KOTLIN_OUTPUT)}`);+}++main();diff --git a/core/models/scripts/generate-languages.cjs b/core/models/scripts/generate-languages.cjsindex f54a3b6b3..d78daaa19 100644--- a/core/models/scripts/generate-languages.cjs+++ b/core/models/scripts/generate-languages.cjs@@ -5,8 +5,8 @@* Input: core/models/src/defaults/Languages.ts (compiled to dist/defaults/index.js)* Output: apps/server/AliasVault.Client/Main/Models/Languages.cs (C#)*- * The TypeScript clients (browser extension + mobile) import the metadata directly from the- * distributed `@/utils/dist/core/models/defaults`, so only the C# variant needs to be generated.+ * The TypeScript clients (browser extension + mobile) import the metadata directly from+ * `@aliasvault/models/defaults`, so only the C# variant needs to be generated.*/const fs = require('fs');diff --git a/core/models/scripts/generate-password-defaults.cjs b/core/models/scripts/generate-password-defaults.cjsindex 7442a46c5..125b06ab4 100644--- a/core/models/scripts/generate-password-defaults.cjs+++ b/core/models/scripts/generate-password-defaults.cjs@@ -7,7 +7,7 @@* - core/rust/src/password_generator/defaults.rs (Rust)* - apps/server/Databases/AliasClientDb/Models/PasswordGeneratorDefaults.cs (C#)*- * Note: Typescript clients can import the constants directly from the distributed `@/utils/dist/core/models/vault`.+ * Note: Typescript clients import the constants directly from `@aliasvault/models/defaults`.*/const fs = require('fs');diff --git a/core/models/src/defaults/AppDefaults.ts b/core/models/src/defaults/AppDefaults.tsnew file mode 100644index 000000000..6d0609f07--- /dev/null+++ b/core/models/src/defaults/AppDefaults.ts@@ -0,0 +1,22 @@+/**+ * Single source of truth for the client-wide connection defaults shared by every AliasVault client.+ *+ * This file is distributed by core/models/build.sh (scripts/generate-app-defaults.cjs) to the native platforms:+ * - `apps/mobile-app/ios/VaultStoreKit/AppInfo.swift` (Swift)+ * - `apps/mobile-app/android/app/src/main/java/net/aliasvault/app/utils/AppInfo.kt` (Kotlin)+ *+ * The TypeScript clients import the constants directly from `@aliasvault/models/defaults`.+ */++/**+ * The minimum supported AliasVault server (API) version. A client refuses to work against an older server and+ * tells the user to update it. Raise it when a client starts to depend on an endpoint or a response shape that+ * older servers lack.+ */+export const MIN_SERVER_VERSION = '0.12.0-dev';++/** The default AliasVault web client URL. */+export const DEFAULT_CLIENT_URL = 'https://app.aliasvault.com';++/** The default AliasVault web API URL. */+export const DEFAULT_API_URL = 'https://app.aliasvault.com/api';diff --git a/core/models/src/defaults/index.ts b/core/models/src/defaults/index.tsindex 989c97f73..f05b72ac8 100644--- a/core/models/src/defaults/index.ts+++ b/core/models/src/defaults/index.ts@@ -3,3 +3,4 @@*/export * from './PasswordGeneratorDefaults';export * from './Languages';+export * from './AppDefaults';