mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 19:01:08 +02:00
refactor(packages): consolidate 3 credit packages into @manacore/credits
Merged credit-operations + shared-credit-service + shared-credit-ui into @manacore/credits with sub-path exports: - @manacore/credits — operations, costs, service - @manacore/credits/web — Svelte components - @manacore/credits/mobile — React Native components Package count: 47 → 44 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b7e67aef21
commit
11db6c60dc
23 changed files with 100 additions and 293 deletions
|
|
@ -42,7 +42,7 @@
|
|||
"vitest": "^4.0.14"
|
||||
},
|
||||
"dependencies": {
|
||||
"@manacore/credit-operations": "workspace:^",
|
||||
"@manacore/credits": "workspace:^",
|
||||
"@manacore/qr-export": "workspace:*",
|
||||
"@manacore/shared-auth": "workspace:*",
|
||||
"@manacore/shared-auth-ui": "workspace:*",
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
{
|
||||
"name": "@manacore/credit-operations",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "Central credit operation definitions and costs for all Mana apps",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "tsc --watch",
|
||||
"clean": "rm -rf dist",
|
||||
"type-check": "tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"lib": ["ES2020"],
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"noImplicitThis": true,
|
||||
"alwaysStrict": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": false,
|
||||
"moduleResolution": "node",
|
||||
"baseUrl": ".",
|
||||
"esModuleInterop": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
27
packages/credits/package.json
Normal file
27
packages/credits/package.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "@manacore/credits",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "Unified credit package — operations, service, and UI components",
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./web": {
|
||||
"svelte": "./src/web/index.ts",
|
||||
"default": "./src/web/index.ts"
|
||||
},
|
||||
"./mobile": "./src/mobile/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"type-check": "tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"svelte": "^5.0.0",
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"svelte": "^5.0.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { createCreditService } from '@manacore/shared-credit-service';
|
||||
* import { createCreditService } from './createCreditService';
|
||||
* import { auth } from '$lib/stores/auth';
|
||||
*
|
||||
* export const creditService = createCreditService({
|
||||
|
|
@ -29,8 +29,8 @@ import type {
|
|||
PricingResponse,
|
||||
CreditUpdateCallback,
|
||||
StandardOperationType,
|
||||
} from './types';
|
||||
import { DEFAULT_OPERATION_PRICING } from './types';
|
||||
} from './service-types';
|
||||
import { DEFAULT_OPERATION_PRICING } from './service-types';
|
||||
|
||||
/**
|
||||
* Create a credit service instance
|
||||
45
packages/credits/src/index.ts
Normal file
45
packages/credits/src/index.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* @manacore/credits — Unified credit package
|
||||
*
|
||||
* Consolidates credit-operations + shared-credit-service + shared-credit-ui.
|
||||
*
|
||||
* Usage:
|
||||
* - Operations/costs: import { CreditOperationType, CREDIT_COSTS } from '@manacore/credits'
|
||||
* - Service: import { createCreditService } from '@manacore/credits'
|
||||
* - Web UI: import { CreditBalance } from '@manacore/credits/web'
|
||||
* - Mobile UI: import { CreditBalance } from '@manacore/credits/mobile'
|
||||
*/
|
||||
|
||||
// === Operations (costs, types, metadata) ===
|
||||
export {
|
||||
CreditOperationType,
|
||||
CreditCategory,
|
||||
CREDIT_COSTS,
|
||||
OPERATION_METADATA,
|
||||
FREE_OPERATIONS,
|
||||
getCreditCost,
|
||||
getOperationMetadata,
|
||||
getOperationsForApp,
|
||||
getOperationsByCategory,
|
||||
calculateBulkCost,
|
||||
isFreeOperation,
|
||||
isMicroCreditOperation,
|
||||
isAiOperation,
|
||||
formatCreditCost,
|
||||
getPricingTable,
|
||||
isFreeAction,
|
||||
type OperationMetadata,
|
||||
} from './operations';
|
||||
|
||||
// === Service (client-side credit management) ===
|
||||
export { createCreditService, type CreditService } from './createCreditService';
|
||||
export type {
|
||||
CreditServiceConfig,
|
||||
CreditBalance,
|
||||
CreditCheckResponse,
|
||||
CreditConsumptionResponse,
|
||||
PricingResponse,
|
||||
CreditUpdateCallback,
|
||||
StandardOperationType,
|
||||
} from './service-types';
|
||||
export { DEFAULT_OPERATION_PRICING } from './service-types';
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import React from 'react';
|
||||
import { View, Text, TouchableOpacity, ActivityIndicator, StyleSheet } from 'react-native';
|
||||
import { formatCreditCost } from '@manacore/credit-operations';
|
||||
import { formatCreditCost } from './operations';
|
||||
|
||||
interface CreditBalanceProps {
|
||||
/** Current credit balance */
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import React, { useEffect } from 'react';
|
||||
import { View, Text, TouchableOpacity, StyleSheet, Animated } from 'react-native';
|
||||
import { formatCreditCost } from '@manacore/credit-operations';
|
||||
import { formatCreditCost } from './operations';
|
||||
|
||||
interface CreditToastProps {
|
||||
/** The operation name or description */
|
||||
2
packages/credits/src/mobile/index.ts
Normal file
2
packages/credits/src/mobile/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export { CreditBalance } from './CreditBalance';
|
||||
export { CreditToast } from './CreditToast';
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { formatCreditCost } from '@manacore/credit-operations';
|
||||
import { formatCreditCost } from './operations';
|
||||
|
||||
interface Props {
|
||||
/** Current credit balance */
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
getPricingTable,
|
||||
CreditCategory,
|
||||
type CreditOperationType,
|
||||
} from '@manacore/credit-operations';
|
||||
} from './operations';
|
||||
|
||||
interface Props {
|
||||
/** The app to show pricing for (e.g., 'todo', 'chat', 'calendar') */
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { formatCreditCost } from '@manacore/credit-operations';
|
||||
import { formatCreditCost } from './operations';
|
||||
|
||||
interface Props {
|
||||
/** The operation name or description */
|
||||
3
packages/credits/src/web/index.ts
Normal file
3
packages/credits/src/web/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export { default as CreditBalance } from './CreditBalance.svelte';
|
||||
export { default as CreditPricingTable } from './CreditPricingTable.svelte';
|
||||
export { default as CreditToast } from './CreditToast.svelte';
|
||||
14
packages/credits/tsconfig.json
Normal file
14
packages/credits/tsconfig.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "bundler",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"jsx": "react-jsx",
|
||||
"outDir": "dist",
|
||||
"declaration": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.svelte"]
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
"name": "@manacore/shared-credit-service",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"default": "./src/index.ts"
|
||||
}
|
||||
},
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"files": [
|
||||
"src"
|
||||
],
|
||||
"scripts": {
|
||||
"type-check": "tsc --noEmit",
|
||||
"lint": "eslint ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@manacore/shared-subscription-types": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
* @manacore/shared-credit-service
|
||||
*
|
||||
* Shared credit/mana service for the ManaCore monorepo.
|
||||
*
|
||||
* Provides:
|
||||
* - Credit balance fetching and caching
|
||||
* - Operation pricing with fallbacks
|
||||
* - Credit check before operations
|
||||
* - Credit consumption notifications
|
||||
*
|
||||
* @example Basic usage
|
||||
* ```ts
|
||||
* import { createCreditService } from '@manacore/shared-credit-service';
|
||||
*
|
||||
* const creditService = createCreditService({
|
||||
* apiUrl: 'https://api.myapp.com',
|
||||
* getAuthToken: async () => localStorage.getItem('token')
|
||||
* });
|
||||
*
|
||||
* // Initialize on app startup
|
||||
* await creditService.initialize();
|
||||
*
|
||||
* // Check balance before operation
|
||||
* const check = await creditService.checkOperationBalance('STORY_CREATION');
|
||||
* if (!check.hasEnoughCredits) {
|
||||
* showInsufficientCreditsModal(check.deficit);
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
* // After successful operation, notify listeners
|
||||
* creditService.triggerCreditUpdate(10, 'STORY_CREATION');
|
||||
* ```
|
||||
*
|
||||
* @example With Svelte store integration
|
||||
* ```ts
|
||||
* // creditService.ts
|
||||
* import { createCreditService } from '@manacore/shared-credit-service';
|
||||
* import { auth } from '$lib/stores/auth';
|
||||
*
|
||||
* export const creditService = createCreditService({
|
||||
* apiUrl: import.meta.env.VITE_API_URL,
|
||||
* pricingEndpoint: '/credits/pricing',
|
||||
* getAuthToken: () => auth.getToken()
|
||||
* });
|
||||
*
|
||||
* // creditStore.svelte.ts
|
||||
* import { creditService } from './creditService';
|
||||
*
|
||||
* let balance = $state<number>(0);
|
||||
*
|
||||
* // Listen for credit updates
|
||||
* creditService.onCreditUpdate((consumed) => {
|
||||
* balance -= consumed;
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
|
||||
// Factory function
|
||||
export { createCreditService } from './createCreditService';
|
||||
export type { CreditService } from './createCreditService';
|
||||
|
||||
// Types
|
||||
export type {
|
||||
CreditServiceConfig,
|
||||
CreditBalance,
|
||||
CreditCheckResponse,
|
||||
CreditConsumptionResponse,
|
||||
PricingResponse,
|
||||
CreditUpdateCallback,
|
||||
StandardOperationType,
|
||||
} from './types';
|
||||
|
||||
// Constants
|
||||
export { DEFAULT_OPERATION_PRICING } from './types';
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"lib": ["ES2022", "DOM"],
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
{
|
||||
"name": "@manacore/shared-credit-ui",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "Credit system UI components for web (Svelte) and mobile (React Native)",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/web/index.ts",
|
||||
"svelte": "./src/web/index.ts",
|
||||
"default": "./src/web/index.ts"
|
||||
},
|
||||
"./web": {
|
||||
"types": "./src/web/index.ts",
|
||||
"svelte": "./src/web/index.ts",
|
||||
"default": "./src/web/index.ts"
|
||||
},
|
||||
"./mobile": {
|
||||
"types": "./src/mobile/index.ts",
|
||||
"default": "./src/mobile/index.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"type-check": "svelte-check --tsconfig ./tsconfig.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@manacore/credit-operations": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"svelte": "^5.0.0",
|
||||
"react": "^18.0.0",
|
||||
"react-native": "^0.74.0 || ^0.75.0 || ^0.76.0 || ^0.77.0 || ^0.78.0 || ^0.79.0 || ^0.80.0 || ^0.81.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"svelte": {
|
||||
"optional": true
|
||||
},
|
||||
"react": {
|
||||
"optional": true
|
||||
},
|
||||
"react-native": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.0.0",
|
||||
"@types/react-native": "^0.73.0",
|
||||
"svelte": "^5.0.0",
|
||||
"svelte-check": "^4.0.0",
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
/**
|
||||
* Credit UI components for mobile (React Native)
|
||||
*/
|
||||
|
||||
export { CreditBalance } from './CreditBalance';
|
||||
export { CreditToast } from './CreditToast';
|
||||
|
||||
// Re-export useful functions from credit-operations
|
||||
export {
|
||||
formatCreditCost,
|
||||
getCreditCost,
|
||||
getOperationMetadata,
|
||||
getPricingTable,
|
||||
isFreeOperation,
|
||||
isMicroCreditOperation,
|
||||
isAiOperation,
|
||||
CreditOperationType,
|
||||
CreditCategory,
|
||||
} from '@manacore/credit-operations';
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
* Credit UI components for web (Svelte 5)
|
||||
*/
|
||||
|
||||
export { default as CreditBalance } from './CreditBalance.svelte';
|
||||
export { default as CreditToast } from './CreditToast.svelte';
|
||||
export { default as CreditPricingTable } from './CreditPricingTable.svelte';
|
||||
|
||||
// Re-export useful functions from credit-operations
|
||||
export {
|
||||
formatCreditCost,
|
||||
getCreditCost,
|
||||
getOperationMetadata,
|
||||
getPricingTable,
|
||||
isFreeOperation,
|
||||
isMicroCreditOperation,
|
||||
isAiOperation,
|
||||
CreditOperationType,
|
||||
CreditCategory,
|
||||
} from '@manacore/credit-operations';
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noImplicitReturns": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"jsx": "react-native",
|
||||
"types": ["svelte", "react", "react-native"]
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue