Skip to content

Commit 7473077

Browse files
committed
feat: Refactor API and shared services, update configurations, and add integration tests
1 parent c784a4d commit 7473077

File tree

13 files changed

+162
-35
lines changed

13 files changed

+162
-35
lines changed

jest.config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { Config } from '@jest/types';
2+
3+
const config: Config.InitialOptions = {
4+
preset: 'ts-jest',
5+
testEnvironment: 'node',
6+
moduleFileExtensions: ['ts', 'js', 'json'],
7+
transform: {
8+
'^.+\\.ts$': 'ts-jest',
9+
},
10+
testMatch: ['**/tests/**/*.test.ts'],
11+
moduleNameMapper: {
12+
'^@mixcore/(.*)$': '<rootDir>/packages/$1/src',
13+
},
14+
globals: {
15+
'ts-jest': {
16+
tsconfig: 'tsconfig.base.json',
17+
},
18+
},
19+
};
20+
21+
export default config;

packages/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "eslint src --ext .ts"
1212
},
1313
"dependencies": {
14-
"@mixcore/config": "workspace:*",
14+
"@mixcore/shared": "workspace:*",
1515
"@mixcore/file": "workspace:*",
1616
"@mixcore/template": "workspace:*",
1717
"@mixcore/user": "workspace:*"

packages/api/src/api-services.ts

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
1-
/**
2-
* Generic API result type for Mixcore SDK
3-
*
4-
* @remarks
5-
* Used for all API responses. Extend or narrow as needed per endpoint.
6-
* @public
7-
*/
8-
export interface ApiResult {
9-
/** Indicates if the API call was successful */
10-
isSucceed: boolean;
11-
/** Response data, if any */
12-
data?: any;
13-
/** Error messages, if any */
14-
errors?: string[];
15-
/** Additional fields for extensibility */
16-
[key: string]: any;
17-
}
1+
import type { ApiServiceConfig } from '@mixcore/shared';
2+
import type { ApiResult, RestApiResult } from '@mixcore/shared';
3+
4+
export type { ApiResult, RestApiResult };
185

19-
/**
20-
* REST API result type for Mixcore SDK
21-
*
22-
* @remarks
23-
* Used for RESTful API responses. Inherits from ApiResult.
24-
* @public
25-
*/
26-
export interface RestApiResult extends ApiResult {}
276
/**
287
* ApiService
298
* Framework-agnostic, TypeScript-native API client for Mixcore
@@ -32,11 +11,6 @@ export interface RestApiResult extends ApiResult {}
3211
* Refactored from legacy AngularJS service. All SPA dependencies removed.
3312
* Configuration is injected via constructor.
3413
*/
35-
export interface ApiServiceConfig {
36-
apiBaseUrl: string;
37-
apiKey?: string;
38-
[key: string]: any;
39-
}
4014

4115
export type ApiServiceHook = {
4216
onRequest?: (req: RequestInit & { url: string }) => void | Promise<void>;

packages/api/src/createMixcoreSdk.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { ApiService } from './api-services';
44
import { UserServices } from '@mixcore/user';
55
import { TemplateService } from '@mixcore/template';
6+
import { FileServices } from '@mixcore/shared';
67
import { FileServicesPortal } from '@mixcore/file';
78
import { ConfigurationServices } from '@mixcore/config';
89
// ...import other domain services as needed

packages/api/tsup.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { defineConfig } from 'tsup';
33
export default defineConfig({
44
entry: ['src/index.ts'],
55
format: ['esm', 'cjs'],
6-
dts: true,
6+
dts: {
7+
resolve: true,
8+
compilerOptions: {
9+
rootDir: 'src',
10+
outDir: 'dist'
11+
}
12+
},
713
splitting: false,
814
sourcemap: true,
915
clean: true,

packages/config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "eslint src --ext .ts"
1212
},
1313
"dependencies": {
14-
"@mixcore/api": "workspace:*"
14+
"@mixcore/shared": "workspace:*"
1515
},
1616
"license": "SEE LICENSE IN LICENSE",
1717
"repository": "https://github.com/mixcore/javascript-sdk",

packages/config/src/configuration-services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ApiService } from '@mixcore/api';
2+
import { ApiServiceConfig } from '@mixcore/shared';
23

34
/**
45
* ConfigurationServices

packages/file/src/file-services.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ApiService } from '@mixcore/api';
2+
import type { FileServices } from '@mixcore/shared';
23

3-
export class FileServicesPortal {
4+
export class FileServicesPortal implements FileServices {
45
private api: ApiService;
56
private prefixUrl = '/file/';
67

packages/file/tsup.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { defineConfig } from 'tsup';
33
export default defineConfig({
44
entry: ['src/index.ts'],
55
format: ['esm', 'cjs'],
6-
dts: true,
6+
dts: {
7+
resolve: true,
8+
compilerOptions: {
9+
rootDir: 'src',
10+
outDir: 'dist'
11+
}
12+
},
713
splitting: false,
814
sourcemap: true,
915
clean: true,

packages/shared/src/api-types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Shared API types for Mixcore SDK
3+
*
4+
* Contains types that need to be shared across packages to avoid circular dependencies
5+
*/
6+
export interface ApiServiceConfig {
7+
apiBaseUrl: string;
8+
apiKey?: string;
9+
[key: string]: any;
10+
}
11+
12+
export interface ApiResult {
13+
isSucceed: boolean;
14+
data?: any;
15+
errors?: string[];
16+
[key: string]: any;
17+
}
18+
19+
export interface RestApiResult extends ApiResult {}

0 commit comments

Comments
 (0)