fix(platform): add temporary invttrdg product fallback

This commit is contained in:
root 2026-05-05 21:07:26 +00:00
parent 42f60cb286
commit 8f449a5ee5

View File

@ -7,6 +7,28 @@ import * as repository from './repository.js';
import type { ProductDoc } from './types.js';
const productCache = new Map<string, ProductDoc>();
const TEMPORARY_FALLBACK_PRODUCTS: Record<string, ProductDoc> = {
// TODO(platform): remove this hardcoded invttrdg fallback after creating the
// real product in the platform-service /products registry.
invttrdg: {
id: 'invttrdg',
productId: 'invttrdg',
displayName: 'Investment Trading',
licensePrefix: 'INVTTRDG',
packageName: 'com.bytelyst.invttrdg',
defaultPlan: 'free',
trialDays: 14,
deviceLimits: {
free: 1,
pro: 3,
enterprise: 10,
},
websiteUrl: 'https://invttrdg.bytelyst.com',
status: 'active',
createdAt: '2026-05-05T00:00:00.000Z',
updatedAt: '2026-05-05T00:00:00.000Z',
},
};
/**
* Load all products from Cosmos into memory.
@ -20,17 +42,20 @@ export async function loadProductCache(): Promise<void> {
/** Get a product by ID from cache. */
export function getProduct(productId: string): ProductDoc | undefined {
return productCache.get(productId);
return productCache.get(productId) ?? TEMPORARY_FALLBACK_PRODUCTS[productId];
}
/** Check if a productId exists in cache. */
export function isValidProduct(productId: string): boolean {
return productCache.has(productId);
return productCache.has(productId) || Boolean(TEMPORARY_FALLBACK_PRODUCTS[productId]);
}
/** Get all cached products. */
export function getAllProducts(): ProductDoc[] {
return Array.from(productCache.values());
return [
...Array.from(productCache.values()),
...Object.values(TEMPORARY_FALLBACK_PRODUCTS).filter(product => !productCache.has(product.id)),
];
}
/** Current cache size (for tests/health). */