# Shared Types Integration for Main and External Apps

**Date:** 2025-01-08  
**Status:** ✅ Completed (with notes)

## Overview

Integrated the `@xtablo/shared-types` package with the `main` and `external` apps by updating the existing `@xtablo/shared` package to re-export types from `@xtablo/shared-types`. This approach maintains backward compatibility for all apps using the shared package.

## Changes Made

### 1. Updated `packages/shared/package.json`

Added `@xtablo/shared-types` as a dependency:

```json
"dependencies": {
  "@xtablo/shared-types": "workspace:*",
  // ... other dependencies
}
```

### 2. Replaced Type Files with Re-exports

All type files in `packages/shared/src/types/` now re-export from `@xtablo/shared-types`:

#### Modified Files:
- `packages/shared/src/types/database.types.ts` - Re-exports Database, Json, Tables, TablesInsert, TablesUpdate
- `packages/shared/src/types/events.types.ts` - Re-exports Event types and legacy compatibility exports
- `packages/shared/src/types/tablos.types.ts` - Re-exports Tablo types with legacy compatibility
- `packages/shared/src/types/removeNull.ts` - Re-exports utility types
- `packages/shared/src/types/kanban.types.ts` - Re-exports all Kanban types
- `packages/shared/src/types/stripe.types.ts` - Re-exports types + keeps helper functions (not pure types)

### 3. Stripe Helper Functions

The `stripe.types.ts` file keeps its helper functions locally since these are runtime functions, not types:
- `isActiveSubscription()`
- `isPastDue()`
- `isCanceled()`
- `formatPrice()`
- `formatInterval()`
- `getSubscriptionStatusText()`
- `getSubscriptionStatusColor()`

These functions import the necessary types from `@xtablo/shared-types` to maintain type safety.

## No Import Changes Required

Because we modified the `@xtablo/shared` package to re-export types from `@xtablo/shared-types`, **no import changes were needed** in the `main` and `external` apps. All existing imports like:

```typescript
import { EventInsertInTablo } from "@xtablo/shared/types/events.types";
import { Database, Tables } from "@xtablo/shared/types/database.types";
```

Continue to work as before, but now resolve to the centralized types in `@xtablo/shared-types`.

## Verification

### ✅ Successful Tests

- `turbo typecheck --filter=@xtablo/shared` - Passed
- `turbo typecheck --filter=@xtablo/main` - Passed
- `turbo lint --filter=@xtablo/shared` - Passed

### ⚠️ Known Issues (Pre-existing)

#### External App: Missing Hook

The `@xtablo/external` app has a pre-existing issue unrelated to types:

**Error:**
```
src/EmbeddedBookingPage.tsx(1,10): error TS2305: Module '"@xtablo/shared"' has no exported member 'useCreateTabloWithOwner'.
src/FloatingBookingWidget.tsx(1,10): error TS2305: Module '"@xtablo/shared"' has no exported member 'useCreateTabloWithOwner'.
```

**Status:** This is a missing hook that was never implemented. The external app imports it but it doesn't exist in the codebase.

**Affected Files:**
- `apps/external/src/EmbeddedBookingPage.tsx`
- `apps/external/src/FloatingBookingWidget.tsx`

**Recommended Action:** Implement the `useCreateTabloWithOwner` hook in `packages/shared/src/hooks/` or remove the unused imports if the functionality was replaced.

## Benefits

1. **Single Source of Truth** - All database and domain types now come from `@xtablo/shared-types`
2. **Zero Migration Effort** - No import changes needed in consuming apps
3. **Backward Compatible** - Maintains all existing import paths
4. **Type Safety** - All apps now share the exact same type definitions
5. **Consistency** - Types are guaranteed to be consistent across API, main, and external apps

## Package Dependencies

```
@xtablo/shared-types (base types)
        ↓
@xtablo/shared (re-exports types + adds hooks/utils)
        ↓
@xtablo/main, @xtablo/external (consume via @xtablo/shared)
@xtablo/api (consume directly from @xtablo/shared-types)
```

## Files Modified

- `packages/shared/package.json`
- `packages/shared/src/types/database.types.ts`
- `packages/shared/src/types/events.types.ts`
- `packages/shared/src/types/tablos.types.ts`
- `packages/shared/src/types/removeNull.ts`
- `packages/shared/src/types/kanban.types.ts`
- `packages/shared/src/types/stripe.types.ts`

## Related Documentation

- [API Shared Types Migration](./API_SHARED_TYPES_MIGRATION.md) - Migration of API app to use shared types
- [Types Package](./TYPES_PACKAGE.md) - Overview of the shared-types package

