From 7d5ed86724a98824ed831058ce44a08cc289b331 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Sat, 28 Feb 2026 12:32:11 -0800 Subject: [PATCH] feat: add universal prep-consumer.sh for portable Docker/CI builds + fix tsc errors --- scripts/prep-consumer.sh | 114 ++++++++++++++++++ .../src/modules/delivery/repository.ts | 2 +- .../src/modules/jobs/repository.ts | 2 +- 3 files changed, 116 insertions(+), 2 deletions(-) create mode 100755 scripts/prep-consumer.sh diff --git a/scripts/prep-consumer.sh b/scripts/prep-consumer.sh new file mode 100755 index 00000000..4f6dd91f --- /dev/null +++ b/scripts/prep-consumer.sh @@ -0,0 +1,114 @@ +#!/usr/bin/env bash +# prep-consumer.sh — Pack @bytelyst/* packages as tarballs and rewrite +# a consumer's package.json file: refs so builds are fully self-contained. +# +# This script lives in learning_ai_common_plat and can be called by any +# consumer repo that uses file: refs to @bytelyst/* packages. +# +# Usage: +# ../learning_ai_common_plat/scripts/prep-consumer.sh +# ../learning_ai_common_plat/scripts/prep-consumer.sh --restore +# +# Prerequisites: +# cd learning_ai_common_plat && pnpm build +# +# Example: +# # From learning_voice_ai_agent: +# ../learning_ai_common_plat/scripts/prep-consumer.sh user-dashboard-web +# +# # From learning_ai_clock: +# ../learning_ai_common_plat/scripts/prep-consumer.sh web +# +# # Restore original package.json: +# ../learning_ai_common_plat/scripts/prep-consumer.sh user-dashboard-web --restore +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +COMMON_PLAT="$(cd "$SCRIPT_DIR/.." && pwd)" + +if [ $# -lt 1 ]; then + echo "Usage: $0 [--restore]" + echo " target-dir: path to consumer directory containing package.json" + exit 1 +fi + +TARGET_DIR="$1" + +# Resolve relative paths +if [[ ! "$TARGET_DIR" = /* ]]; then + TARGET_DIR="$(pwd)/$TARGET_DIR" +fi + +if [ ! -f "$TARGET_DIR/package.json" ]; then + echo "❌ No package.json found at $TARGET_DIR" + exit 1 +fi + +# ── Restore mode ────────────────────────────────────────────── +if [[ "${2:-}" == "--restore" ]]; then + BACKUP="$TARGET_DIR/package.json.bak" + if [ -f "$BACKUP" ]; then + mv "$BACKUP" "$TARGET_DIR/package.json" + rm -rf "$TARGET_DIR/.docker-deps" + echo "✅ Restored $TARGET_DIR/package.json" + else + echo "⚠️ No backup found at $BACKUP" + fi + exit 0 +fi + +# ── Validate packages are built ────────────────────────────── +if [ ! -d "$COMMON_PLAT/packages" ]; then + echo "❌ Cannot find packages/ in $COMMON_PLAT" + exit 1 +fi + +# ── Pack + rewrite ──────────────────────────────────────────── +DEPS_DIR="$TARGET_DIR/.docker-deps" +rm -rf "$DEPS_DIR" +mkdir -p "$DEPS_DIR" + +# Back up original package.json +cp "$TARGET_DIR/package.json" "$TARGET_DIR/package.json.bak" + +DIRNAME="$(basename "$TARGET_DIR")" +echo "📦 Prepping $DIRNAME..." + +# Find all @bytelyst/* file: refs in package.json +PKGS=$(grep -oE '"@bytelyst/[^"]+": *"file:[^"]+"' "$TARGET_DIR/package.json" | grep -oE '@bytelyst/[^"]+' || true) + +if [ -z "$PKGS" ]; then + echo " ℹ️ No @bytelyst/* file: refs found — nothing to do" + rm -f "$TARGET_DIR/package.json.bak" + rm -rf "$DEPS_DIR" + exit 0 +fi + +COUNT=0 +for scoped_name in $PKGS; do + pkg_short="${scoped_name#@bytelyst/}" + PKG_DIR="$COMMON_PLAT/packages/$pkg_short" + + if [ ! -d "$PKG_DIR" ]; then + echo " ⚠️ Package $pkg_short not found in $COMMON_PLAT/packages/" + continue + fi + + if [ ! -d "$PKG_DIR/dist" ]; then + echo " ⚠️ $pkg_short has no dist/ — run 'pnpm build' in common plat first" + continue + fi + + # Pack the package into a tarball + TARBALL=$(cd "$PKG_DIR" && npm pack --pack-destination "$DEPS_DIR" 2>/dev/null | tail -1) + echo " 📦 $pkg_short → $TARBALL" + + # Rewrite the file: ref in package.json to point to the local tarball + sed -i.tmp "s|\"${scoped_name}\": *\"file:[^\"]*\"|\"${scoped_name}\": \"file:.docker-deps/${TARBALL}\"|" "$TARGET_DIR/package.json" + rm -f "$TARGET_DIR/package.json.tmp" + COUNT=$((COUNT + 1)) +done + +echo " ✅ $DIRNAME ready ($COUNT tarballs in .docker-deps/)" +echo "" +echo " Restore with: $0 $1 --restore" diff --git a/services/platform-service/src/modules/delivery/repository.ts b/services/platform-service/src/modules/delivery/repository.ts index 44451a02..23727e3a 100644 --- a/services/platform-service/src/modules/delivery/repository.ts +++ b/services/platform-service/src/modules/delivery/repository.ts @@ -23,7 +23,7 @@ export async function listDeliveryLogs( ): Promise { const limit = options?.limit ?? 50; let query = 'SELECT TOP @limit * FROM c WHERE STARTSWITH(c.pk, @prefix)'; - const parameters: Array<{ name: string; value: unknown }> = [ + const parameters: Array<{ name: string; value: string | number }> = [ { name: '@limit', value: Math.min(limit, 200) }, { name: '@prefix', value: productId }, ]; diff --git a/services/platform-service/src/modules/jobs/repository.ts b/services/platform-service/src/modules/jobs/repository.ts index 81600170..b26a78f9 100644 --- a/services/platform-service/src/modules/jobs/repository.ts +++ b/services/platform-service/src/modules/jobs/repository.ts @@ -36,7 +36,7 @@ export async function getJobDefinition(id: string, productId: string): Promise { const { resource } = await defsContainer().items.upsert(doc); - return resource as JobDefinitionDoc; + return resource as unknown as JobDefinitionDoc; } export async function updateJobDefinition(